1
如何获取按钮对象的大小?如何获得tkinter Button的大小?
如果我做的:
quitButton = Button(self, text="Quit", command=self.quit)
_x = quitButton.winfo_width()
_y = quitButton.winfo_height()
print _x, _y
它打印1 1
。
我在做什么错?
如何获取按钮对象的大小?如何获得tkinter Button的大小?
如果我做的:
quitButton = Button(self, text="Quit", command=self.quit)
_x = quitButton.winfo_width()
_y = quitButton.winfo_height()
print _x, _y
它打印1 1
。
我在做什么错?
尺寸将为1x1,直到它实际绘制在屏幕上,因为尺寸部分受其管理方式的控制(pack
,grid
等)。
当你把它放在屏幕上(pack
,grid
等)使它被绘制后,你可以调用self.update()。一旦绘制,winfo_width
和winfo_height
命令将起作用。
您还没有设置按钮的大小,因此它是1加1. –
使用'quitButton.configure(width = desiredWidth,height = desiredHeight)' –