Tkinter Problem

Discussion in 'Python' started by Maboroshi, Oct 23, 2004.

  1. Maboroshi

    Maboroshi Guest

    Why when I use the sticky command with the grid layout manager won't my
    Listbox expand it stays in the center maybe I am missing something but
    from every tutorial I see it says to do it this way

    I am running Python2.3.4 on winxp I haven't tried it on linux yet

    Any Ideas are appreciated

    Let me know if I am not being clear enough

    Cheers

    Andrew


    from Tkinter import *


    class App(Frame):
    def __init__(self, master=None):
    Frame.__init__(self, master)
    self.grid()
    self.createWidgets()

    def createWidgets(self):
    self.listbox = Listbox(self)
    # RIGHT HERE THIS WON'T EXPAND TO FILL
    self.listbox.grid(row=0, column=0, rowspan=3, sticky=N+E+S+W)

    self.connect = Button(self, text="Connect")
    self.connect.grid(row=0, column=1)
    self.execute = Button(self, text="Execute")
    self.execute.grid(row=1, column=1)
    self.disconnect = Button(self, text="Disconnect")
    self.disconnect.grid(row=2, column=1)

    self.entry = Entry(self)
    self.entry.grid(row=3, column=0, columnspan=2, sticky=E+W)


    app = App()
    app.master.title("MySQL DB Project")
    app.master.minsize(400, 300)
    app.mainloop()
     
    Maboroshi, Oct 23, 2004
    #1
    1. Advertising

  2. Maboroshi

    Peter Otten Guest

    Maboroshi wrote:

    > Why when I use the sticky command with the grid layout manager won't my
    > Listbox expand it stays in the center maybe I am missing something but
    > from every tutorial I see it says to do it this way
    >
    > I am running Python2.3.4 on winxp I haven't tried it on linux yet
    >
    > Any Ideas are appreciated
    >
    > Let me know if I am not being clear enough
    >
    > Cheers
    >
    > Andrew
    >
    >
    > from Tkinter import *
    >
    >
    > class App(Frame):
    > def __init__(self, master=None):
    > Frame.__init__(self, master)


    Remove

    > self.grid()


    This means you have an additional grid containing a single control (the
    Frame). Use a packer instead and make sure it consumes any extra space:

    self.pack(fill=BOTH, expand=True)

    > self.createWidgets()
    >
    > def createWidgets(self):
    > self.listbox = Listbox(self)
    > # RIGHT HERE THIS WON'T EXPAND TO FILL
    > self.listbox.grid(row=0, column=0, rowspan=3, sticky=N+E+S+W)


    You can configure the cell (0, 0) to consume any extra space:

    self.rowconfigure(0, weight=1)
    self.columnconfigure(0, weight=1)

    >
    > self.connect = Button(self, text="Connect")
    > self.connect.grid(row=0, column=1)
    > self.execute = Button(self, text="Execute")
    > self.execute.grid(row=1, column=1)
    > self.disconnect = Button(self, text="Disconnect")
    > self.disconnect.grid(row=2, column=1)
    >
    > self.entry = Entry(self)
    > self.entry.grid(row=3, column=0, columnspan=2, sticky=E+W)
    >
    >
    > app = App()
    > app.master.title("MySQL DB Project")
    > app.master.minsize(400, 300)
    > app.mainloop()


    The Entry and Listbox widgets should grow now as expected. To distribute the
    Buttons smoothly, you can either set the weight of columns 1 and 2 or put
    all three of them in an extra Frame (which I would prefer).

    Peter
     
    Peter Otten, Oct 24, 2004
    #2
    1. Advertising

  3. Maboroshi

    Maboroshi Guest

    Hey Thank you works now

    Cheers

    Andrew
     
    Maboroshi, Oct 24, 2004
    #3
    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:
    517
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    468
    Jeff Epler
    Aug 23, 2004
  3. Pierre Dagenais
    Replies:
    0
    Views:
    328
    Pierre Dagenais
    Aug 3, 2008
  4. Hidekazu IWAKI
    Replies:
    1
    Views:
    390
    Peter Otten
    Dec 14, 2009
  5. Hidekazu IWAKI
    Replies:
    0
    Views:
    535
    Hidekazu IWAKI
    Dec 15, 2009
Loading...

Share This Page