I'm trying to line up some label and canvas widgets. To do so I need to know how wide my label boxes are. I'd like my widget to auto-adjust if the user changes the system font size, so I don't want to hard code 12 pixels per character. If I measure the label widget it's always 1 pixel wide. Until I call.update(), then I get the correct value. But.update() puts a window onscreen with my label, said window then goes away when I finally pack my final widgets. But this causes an unwelcome flash when I first put up the widget.
So, how can I measure a label widget without.update()'ing it? Or how can I.update() a widget without having it display onscreen? I'm using Python if it matters.
Withdraw the window before calling update. The command you want is wm_withdraw
root = Tk()
root.wm_withdraw()
<your code here>
root.wm_deiconify()
However, if your real problem is lining up widgets you usually don't need to know the size of widgets. Use the grid geometry manager. Get out a piece of graph paper and lay your widgets out on it. Feel free to span as many squares as necessary for each widget. The design can then translate easily to a series of grid calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.