473,410 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

pack() and the division of vertical space

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
2 1468
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Applebrown | last post by:
Hello, basically, I'm just learning intermediate CSS and trying to convert my old table webpage completely to CSS. Hoorah, right? Well, it's not quite going as planned. It's an extremely simple...
16
by: Uncle Pirate | last post by:
This has me stumped. I am trying to use as little space as possible at the top of my document but Firefox/Mozilla insists on placing vertical space before any element. IE displays it correctly...
0
by: Penguin | last post by:
Using Access 97, I've created a grading sheet. To save space, the subjects are in vertical columns on a sub-report, like so: Math Spelling Reading N C T A A E U A I ...
7
by: bienwell | last post by:
Hi, I'm using the CheckBoxList control in ASP.NET for Web development. This checkboxlist is bound by the database. If we have more items for this checkbox list, it takes space on the page. I...
1
by: PaulB | last post by:
In my application, I have many forms. Some of these forms contains some labels, which are placed in the header section, and act as a column header. Because of the available space, the orientation...
1
by: Mark Fitzpatrick | last post by:
I haven't seen anyone mention it here yet so I thought it would be worth noting that MS has apparently released VS 2005 Service Pack 1. It's available at:...
1
by: dave8421 | last post by:
Hi, I have a (strict) html document with the following portion: <ul> <li><img alt="" src="images/image1.jpg" /></li> <li><img alt="" src="images/image2.jpg" /></li> <li><img alt=""...
1
by: platoon1sc | last post by:
Hi guys.I have a problem with Internet Explorer in my web-application. I have a vertical scrollbar into my jsps but firefox show the vertical srollbar, but IE doesn't. IE show a blank space where...
2
Jezternz
by: Jezternz | last post by:
Okay basicly, I have a division inside a division. <html><body> <div id="container"> <div id="header">Main image</div> </div> </body> </html> and I want the container to grow as the the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.