Discussion:
Tkinter - getting canvas window size
Rick Pasotto
2001-09-18 22:08:39 UTC
Permalink
On Tue, 18 Sep 2001 17:41:51 GMT in comp.lang.python, Fredrik Lundh
Why do the print statements in the following program show zero?
"cget" returns the option value as specified (or in this case, the
default value), not the actual size.
How do I get the actual size? The packed label might or might not
contain a nl. I don't necessarily know the font size. I need to know
the height of the frame (inside the canvas.create_window()) so I can
position another one underneath it.
How can I figure out the size of the frame?
Use winfo_width/height (current size) or winfo_reqwidth/reqheight
(requested size). the latter is usually what you want.
This always gives '1' as an answer no matter the actual size.
winfo_geometry also always gives 1x1+0+0.

How do I get this to work with the integer that canvas.create_window()
returns?
http://www.pythonware.com/library/tkinter/introduction/basic-widget-methods.htm
=> Window Related Information
This is not helping me for widgets placed on a canvas.
--
How could men dream of blaming themselves for their woes when they
have been persuaded that by nature they are inert, that the source
of all action, and consequently of all responsibility, lies outside
themselves, in the will of the sovereign and of the lawgiver?
-- Fr?d?ric Bastiat (1801-1850)
Rick Pasotto rickp at telocity.com http://www.niof.net
Fredrik Lundh
2001-09-18 17:41:51 UTC
Permalink
Why do the print statements in the following program show zero?
"cget" returns the option value as specified (or in this case, the
default value), not the actual size.
How can I figure out the size of the frame?
Use winfo_width/height (current size) or winfo_reqwidth/reqheight
(requested size). the latter is usually what you want.

more info here:

http://www.pythonware.com/library/tkinter/introduction/basic-widget-methods.htm
=> Window Related Information

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
Rick Pasotto
2001-09-18 16:35:48 UTC
Permalink
Why do the print statements in the following program show zero?
How can I figure out the size of the frame?

from Tkinter import *

w = Tk()
cnv = Canvas(w,bg='white',relief=SUNKEN)
cnv.config(width=400,height=200)
cnv.pack(side=LEFT,expand=YES,fill=BOTH)

f = Frame(cnv,relief=GROOVE,borderwidth=2)
for j in range(5):
l = Label(f,text='label: %2d' % (j),
relief=GROOVE,borderwidth=2,padx=5)
l.pack(side=LEFT,expand=YES,fill=X,padx=5,pady=2)
f.pack()
cw = cnv.create_window(20,20,window=f,anchor=NW)

print f.cget('height'),f.cget('width')
print cnv.itemcget(cw,'height'), cnv.itemcget(cw,'width')

w.mainloop()
--
Property is prior to law; the sole function of the law is to
safeguard the right to property wherever it exists, wherever it is
formed, in whatever manner the worker produces it, whether
individually or in association, provided that he respects the
rights of others.
-- Fr?d?ric Bastiat (1801-1850)
Rick Pasotto rickp at telocity.com http://www.niof.net
Loading...