[Tkinter-discuss] Font change does reflect window size when executed without debugging

John McMonagle jmcmonagle at velseis.com.au
Wed Apr 8 00:19:42 CEST 2009


Madhu Subramaniam wrote:
> Hi,
> Below is an application with a scrollable frame. There is an option to
> change the font size of the text, (using tkFont) thereby changing the
> size of the widgets and the containers.
> this is done by the function 'fontctrl'. The thing i am not able to
> figure out is that the change in window size works when i put a
> breakpoint/debugger (pdb.set_trace()) and exceute them manually in the
> shell. But when i run w/o debugging, then the print statements do not
> show me the change in window size.
> 
> for example, when the font is medium: self2.winfo_height() shows 840
> with debugging but 600 without the debugger in place.

You need to call winfo_reqheight() and winfo_reqwidth() if you want to
get the size that a widget will be once the mainloop runs.  I think the
reason it works in the debugger, is that the mainloop has already started.

You can see the same effect by testing Tkinter in an interactive
interpreter session.


The following code illustrates the difference between using
winfo_height() and winfo_reqheight():

from Tkinter import *
root = Tk()
b = Button(root, text='test')
b.pack()
print b.winfo_height()
print b.winfo_width()
print b.winfo_reqheight()
print b.winfo_reqwidth()
root.mainloop()


When run this yields:

1
1
34
66

Regards,

John



More information about the Tkinter-discuss mailing list