cosmetic Tkinter question

Discussion in 'Python' started by Sean McIlroy, Dec 26, 2004.

  1. Sean McIlroy

    Sean McIlroy Guest

    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?
    Sean McIlroy, Dec 26, 2004
    #1
    1. Advertising

  2. Sean McIlroy

    Michael Fuhr Guest

    (Sean McIlroy) writes:

    > 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.

    --
    Michael Fuhr
    http://www.fuhr.org/~mfuhr/
    Michael Fuhr, Dec 26, 2004
    #2
    1. Advertising

  3. On 26.12.2004, at 16:38, Sean McIlroy wrote:
    > 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 -

    --
    What is mind? -- Doesn't matter.
    What is matter? -- Never mind!
    --
    harold fellermann, Jan 3, 2005
    #3
  4. Sean McIlroy

    Eric Brunel Guest

    Sean McIlroy wrote:
    > 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
    --
    - Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
    PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
    Eric Brunel, Jan 3, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Epler
    Replies:
    0
    Views:
    504
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    450
    Jeff Epler
    Aug 23, 2004
  3. Pierre Dagenais
    Replies:
    0
    Views:
    308
    Pierre Dagenais
    Aug 3, 2008
  4. Cosmetic Surgery Loans

    , Dec 23, 2008, in forum: C Programming
    Replies:
    3
    Views:
    561
    Frithiof Jensen
    Dec 26, 2008
  5. Hidekazu IWAKI
    Replies:
    1
    Views:
    376
    Peter Otten
    Dec 14, 2009
Loading...

Share This Page