[Tkinter-discuss] getting width of a Frame

Michael O'Donnell michael.odonnell at uam.es
Tue Aug 19 07:53:31 CEST 2008

Hi Alex,

  Several issues here.

1)  In some cases, the size a frame will eventually have
depends on what is packed/gridded inside it. So it m,ay not
be possible to tell the size of the frame before adding the list boxes.

The exception here is if you use tell the frame to take the
maximum space (e.g., for pack: expand=True, fill=BOTH
for grid: sticky=NSEW

You can then pack/grid your Frame, and then ask how big it is
using frm.winfo_geometry() or frm.winfo_height() and frm.winfo_width()

2) You cannot get the frame's size until it is packed and displayed.
So, what you can do is something like the following, using update:

from Tkinter import *
tk = Tk()
Label(tk, text="HELLO").pack(side=TOP)
fr.pack(side=TOP, fill=BOTH, expand=True)
print "frame size before update: ", fr.winfo_width(), fr.winfo_height()
print "frame size after update: ", fr.winfo_width(), fr.winfo_height()

Not always possible to do this,


On Tue, Aug 19, 2008 at 5:38 AM, Alexnb <alexnbryan at gmail.com> wrote:
> I have two listBoxes in one Frame. I want to make them the same size. I want
> to make them half of the width of the Frame they are in. I just can't figure
> out how to get the width of a Frame, just a window. Help?
> --
> View this message in context: http://www.nabble.com/getting-width-of-a-Frame-tp19043845p19043845.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

More information about the Tkinter-discuss mailing list