Home > Enterprise >  Python Tkinter: Why are there so many ways to get the width of a widget and what are the differences
Python Tkinter: Why are there so many ways to get the width of a widget and what are the differences

Time:12-26

I have so far discovered four discovered width (or height) related methods and properties of widget (some for them also can be used to get other widget properties). What are the differences between all of them?

  • widget["width"]
  • widget.cget("width")
  • widget.winfo_width()
  • widget.winfo_reqwidth()

(There are also equivalent methods and properties for height).

CodePudding user response:

-the first one(widget["width"]) is just a wrapping of some of the other commands, I can't tell you which one without decompiling the function.

-the second one(widget. cget("width")) is a method to access to variable width using the access to widget object through the getters methods of the object

-the third one(widget.winfo_width()) can be used to know the current width asking to TK's windows manager

-the fourth one (widget.winfo_reqwidth()) can tell you how much the width of the widget was originally when it was opened, or anyway before the widget.update_idletasks () method.

in general, we can say that they all do the same thing but, as you can guess, there are subtle differences that allow you to access the information you are looking for differently, in this case width

  • Related