Re: Tkinter grid layout

Discussion in 'Python' started by Richard Lewis, Jul 6, 2005.

  1. On Wed, 06 Jul 2005 11:44:55 +0100, "Richard Lewis"
    <> said:
    > Hi there,
    >
    > I've got a tree control in Tkinter (using the ESRF Tree module) but I
    > can't get it to layout how I want it.
    >
    > I'd like to have it so that it streches north/south (anchored to the top
    > and bottom), is of a fixed width and is anchored to the left hand side.
    > Here's my code (its derived from one of the examples from the ESRF web
    > site):
    >

    OK, I've changed it so that the Tree and scroll bars are in a single
    Frame and added another Frame on the right hand side to put the rest of
    my stuff in. (Though I believe this is against the principles of grid
    layout management?)

    class MainWindow(Frame):
    def __init__(self, master):
    Frame.__init__(self, master)
    self.document = # new DOM document
    self.create_ui()

    def create_ui(self):
    self.master.protocol("WM_DELETE_WINDOW", self.app_quit)

    self.pack(fill="both")
    self.master.geometry("%dx%d%+d%+d" % (800, 600, 100, 100))
    self.master.title("Site Editor")

    self.create_menu()

    self.create_site_list()

    self.rhs_frame = Frame(master=self, background="#FF0000")
    self.rhs_frame.grid(row=0, column=1, sticky=E+W+N+S)
    self.grid_columnconfigure(1, weight=1)
    self.grid_rowconfigure(0, weight=1)

    label = Label(master=self.rhs_frame, text="FOO")
    label.grid(row=0, column=0)

    def create_site_list(self):
    self.list_model = ListModel(self.document)

    self.site_list_frame = Frame(master=self, width=300,
    background="#00FF00")
    self.site_list_frame.grid(row=0, column=0, sticky=E+W+N+S)

    self.site_list = Tree.Tree(master=self.site_list_frame,\
    root_id="root",\
    root_label="Site",\
    get_contents_callback=self.get_list_item,\
    width=300,height=600)

    self.site_list.grid(row=0, column=0, sticky=E+W+N+S)

    self.site_list_frame.grid_columnconfigure(0, weight=1)
    self.site_list_frame.grid_rowconfigure(0, weight=1)

    vsb = Scrollbar(self.site_list_frame, orient=VERTICAL)
    vsb.grid(row=0, column=1, sticky=NS)
    self.site_list.configure(yscrollcommand=vsb.set)
    vsb.configure(command=self.site_list.yview)

    hsb = Scrollbar(self.site_list_frame, orient=HORIZONTAL)
    hsb.grid(row=1, column=0, sticky=EW)
    self.site_list.configure(xscrollcommand=hsb.set)
    hsb.configure(command=self.site_list.xview)

    self.site_list.focus_set()


    I noticed that I had a pack() call in my create_ui() function which I
    must have pasted in from some example code a while ago. I tried taking
    this out (having read that you shouldn't mix pack and grid) but, of
    course, then there was no layout (or something) and I just got a blank
    window. So I tried using pack(fill="both"). It now fills horizontally
    correctly, but it still doesn't anchor with the bottom. I'm not setting
    any height for the Tree (if I do then it still doesn't anchor with the
    bottom) because I don't want it to have a particular height, just to
    fill the window.

    Am I heading in the right direction?

    Cheers,
    Richard
     
    Richard Lewis, Jul 6, 2005
    #1
    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. Rick Spiewak
    Replies:
    3
    Views:
    3,198
    Rick Spiewak
    Aug 26, 2003
  2. RobertH
    Replies:
    1
    Views:
    747
    Steve C. Orr [MVP, MCSD]
    Nov 4, 2003
  3. NWx
    Replies:
    4
    Views:
    2,992
    Kevin Spencer
    Feb 19, 2004
  4. Andrew Chalk

    Flow layout to grid layout

    Andrew Chalk, Dec 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    561
    Andrew Chalk
    Dec 23, 2005
  5. Replies:
    1
    Views:
    621
    John Timney \(MVP\)
    Jun 19, 2006
Loading...

Share This Page