【发布时间】:2019-05-14 00:53:55
【问题描述】:
我正在使用 Python 和 Tkinter,并且我有一个函数(我们称之为 getWinProperties)在我初始化我的 Frame 时运行,这个函数在我配置宽度和高度(例如self.configure(width=width, height=height))。我需要获取Frames当前的宽高,在函数内部使用,这个函数也需要在frame的初始化之外使用。
当我使用self.winfo_width() 和self.winfo_height() 时,即使在self.update() 之后,我也会得到1 个宽度和1 个高度。
class CustomFrame(Frame):
def __init__(self, width, height):
self.configure(width=width, height=height)
self.getWinProperties()
def getWinProperties(self):
self.update()
width = self.winfo_width()
height = self.winfo_height()
print(width, height)
我希望在初始化框架时,print(width, height) 会打印来自__init__(self, width, height) 的宽度,但它会打印1, 1
【问题讨论】: