By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

pack() and the division of vertical space

P: n/a
I am trying to figure out how to stack two widgets in a frame
vertically so that they both expand horizontally and during vertical
expansion, the top one sticks to the top of the frame and the bottom
one consumes the remaining vertical space. I thought this would do it
but it doesn't. What am I missing?

from Tkinter import *

class AFrame(Frame):
def __init__(self,master,**config):
Frame.__init__(self,master,config)
size=50
self.l1= Label(text="abc",relief="groove")
self.l1.pack(side=TOP,expand=YES,fill=X,anchor=N)
self.l2= Label(text="abc",relief="groove")
self.l2.pack(side=TOP,expand=YES,fill=BOTH)

af= AFrame(None)
af.pack(side=TOP,expand=YES,fill=BOTH)
mainloop()

May 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 31 May 2007 19:45:04 +0200, ch******************@yahoo.com
<ch******************@yahoo.comwrote:
I am trying to figure out how to stack two widgets in a frame
vertically so that they both expand horizontally and during vertical
expansion, the top one sticks to the top of the frame and the bottom
one consumes the remaining vertical space. I thought this would do it
but it doesn't. What am I missing?
[snip code]

For this kind of stuff, don't use pack; use grid. It will be far easier to
get it working, to read afterwards and to maintain, even if it's slightly
more verbose. IMHO, pack should only be used to create rows or columns of
widgets, without any resizing policy, or to put an entire widget into a
container. If you do anything more complicated than that, you'll find grid
much easier to handle.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Jun 1 '07 #2

P: n/a
On Jun 1, 3:13 am, "Eric Brunel" <see.signat...@no.spamwrote:
On Thu, 31 May 2007 19:45:04 +0200, christopherlmarsh...@yahoo.com

<christopherlmarsh...@yahoo.comwrote:
I am trying to figure out how to stack two widgets in a frame
vertically so that they both expand horizontally and during vertical
expansion, the top one sticks to the top of the frame and the bottom
one consumes the remaining vertical space. I thought this would do it
but it doesn't. What am I missing?

[snip code]

For this kind of stuff, don't use pack; use grid. It will be far easier to
get it working, to read afterwards and to maintain, even if it's slightly
more verbose. IMHO, pack should only be used to create rows or columns of
widgets, without any resizing policy, or to put an entire widget into a
container. If you do anything more complicated than that, you'll find grid
much easier to handle.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
Thanks, I basically came to the same conclusion shortly after writing
my post. I got it working with grid like this:

from Tkinter import *

class AFrame(Frame):
def __init__(self,master,**config):
Frame.__init__(self,master,config)
top= self.winfo_toplevel()
top.columnconfigure(0,weight=1)
top.rowconfigure(0,weight=1)
self.grid(row=0,column=0,sticky="NEWS")
self.rowconfigure(0,weight=0)
self.rowconfigure(1,weight=1)
self.columnconfigure(0,weight=1)
self.l1= Label(self,text="abc",relief="groove")
self.l1.grid(row=0,column=0,sticky="NEW")
self.l2= Label(self,text="abc",relief="groove")
self.l2.grid(row=1,column=0,sticky="NEWS")

af= AFrame(None)
mainloop()

Jun 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.