【发布时间】:2018-11-24 16:30:35
【问题描述】:
我正在试验下面的代码来巩固我的一些想法。但是它不会运行,因为直到代码结束之前画布似乎没有任何尺寸,到那时再做任何事情都为时已晚。如何识别画布的尺寸以便在 'divw = int(screen_width / 100)' 行中使用它?
#!/usr/bin/python3
from tkinter import *
window = Tk()
window.title('Timetable')
window.attributes('-zoomed', True)
screen_width = window.winfo_width()
screen_height = window.winfo_height()
canvas = Canvas(window, width = window.winfo_screenwidth(), height = window.winfo_screenheight(), bg='steelblue')
canvas.pack()
image = PhotoImage(file='blank.png')
screen_width = window.winfo_width()
screen_height = window.winfo_height()
divw = int(screen_width / 100)
print (divw)
for i in range(0, divw):
print (i)
canvas.create_image(i * 100+50, 50, anchor = NW, image=image)
mainloop()
【问题讨论】: