How to find out the current widget size in tkinter?

前端 未结 3 2033
不知归路
不知归路 2020-12-03 00:49

I\'m using Python and Tkinter, and I need to know the current dimensions (width, height) of a widget.

I\'ve tried somewidget[\"width\"]

相关标签:
3条回答
  • 2020-12-03 01:22

    somewidget.winfo_width() and somewidget.winfo_height() give 1. You need to update Tk (issue tk.update()) before getting these values.

    0 讨论(0)
  • 2020-12-03 01:28

    Use somewidget.winfo_width() and somewidget.winfo_height() to get the actual widget size, the somewidget['width'] property is only a hint given to the geometry manager.

    0 讨论(0)
  • 2020-12-03 01:32

    You can use the function somewidget.winfo_reqheight() for height and somewidget.winfo_reqwidth() for width, but first don't forget to call the update function of the widget you want to know the dimension somewidget.update(). If you do not call the update function you will get the default value 1.

    0 讨论(0)
提交回复
热议问题