tags:

views:

258

answers:

2

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.

+1  A: 

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.

Bryan Oakley
A: 

Ahhh, hadn't run across withdraw() in my doc perusal.

I did lay out my stuff, and the result is close but somewhat annoying. I want to measure some text boxes to move lines around a few pixels to make for a cleaner look.

My app is a canvas widget with some lines and ovals on it, with Labels at the edges labeling lines. My issue is the Labels along the top edge aren't quite lining up with their lines in an aesthetically pleasing manner.