cosmetic Tkinter question

S

Sean McIlroy

I've got a bunch of Frames, all packed into the root window with
side=TOP, and in each Frame I've got a Checkbutton packed with
side=LEFT. I expected the Checkbuttons to be flush with the left edge
of the window, but they're not, and it looks a little gross. How do I
get them to align?
 
M

Michael Fuhr

I've got a bunch of Frames, all packed into the root window with
side=TOP, and in each Frame I've got a Checkbutton packed with
side=LEFT. I expected the Checkbuttons to be flush with the left edge
of the window, but they're not, and it looks a little gross. How do I
get them to align?

You can see what's happening if you create the frames with options
like relief=RIDGE, bd=1. Read up on how the packer works and how
to control layout with expand, fill, and anchor.
 
H

harold fellermann

I've got a bunch of Frames, all packed into the root window with
side=TOP, and in each Frame I've got a Checkbutton packed with
side=LEFT. I expected the Checkbuttons to be flush with the left edge
of the window, but they're not, and it looks a little gross. How do I
get them to align?

if you pack the frames with option fill=X they should be well aligned --
This commands the frame to use all available space in the horizontal
direction:

your_frame.pack(side=TOP,fill=X)
your_button.pack(side=LEFT)


- harold -
 
E

Eric Brunel

Sean said:
I've got a bunch of Frames, all packed into the root window with
side=TOP, and in each Frame I've got a Checkbutton packed with
side=LEFT. I expected the Checkbuttons to be flush with the left edge
of the window, but they're not, and it looks a little gross. How do I
get them to align?

The standard behaviour for frames is to adapt to their contents, and packing
them with side=TOP without any other option will center them in their container.

So you have a few solutions to your problem:
- use the anchor option when packing the frames; setting anchor=W should do what
you want
- use fill=X when packing the frames, as Harold said. This expands the frame to
the whole width of its container, so this should align the check-buttons (if it
doesn't work, add the option expand=1 to force the frame to be wider than its
contents)

A silly question BTW: why do you use frames? If you have only check-buttons in
them, you do not need them:

from Tkinter import *
root = Tk()
for i in range(0, 101, 20):
b = Checkbutton(root, text='Option %s' % i)
b.pack(side=TOP, anchor=W)
root.mainloop()

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top