Tkinter Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maboroshi

    #1

    Tkinter Problem

    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.createWidg ets()

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

    self.connect = Button(self, text="Connect")
    self.connect.gr id(row=0, column=1)
    self.execute = Button(self, text="Execute")
    self.execute.gr id(row=1, column=1)
    self.disconnect = Button(self, text="Disconnec t")
    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.titl e("MySQL DB Project")
    app.master.mins ize(400, 300)
    app.mainloop()
  • Peter Otten

    #2
    Re: Tkinter Problem

    Maboroshi wrote:
    [color=blue]
    > 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)[/color]

    Remove
    [color=blue]
    > self.grid()[/color]

    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)
    [color=blue]
    > self.createWidg ets()
    >
    > def createWidgets(s elf):
    > self.listbox = Listbox(self)
    > # RIGHT HERE THIS WON'T EXPAND TO FILL
    > self.listbox.gr id(row=0, column=0, rowspan=3, sticky=N+E+S+W)[/color]

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

    self.rowconfigu re(0, weight=1)
    self.columnconf igure(0, weight=1)
    [color=blue]
    >
    > self.connect = Button(self, text="Connect")
    > self.connect.gr id(row=0, column=1)
    > self.execute = Button(self, text="Execute")
    > self.execute.gr id(row=1, column=1)
    > self.disconnect = Button(self, text="Disconnec t")
    > 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.titl e("MySQL DB Project")
    > app.master.mins ize(400, 300)
    > app.mainloop()[/color]

    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

    Comment

    • Maboroshi

      #3
      Re: Tkinter Problem

      Hey Thank you works now

      Cheers

      Andrew

      Comment

      Working...