Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter Problem

Reply
Thread Tools

Tkinter Problem

 
 
Maboroshi
Guest
Posts: n/a
 
      10-23-2004
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()
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      10-24-2004
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
 
Reply With Quote
 
 
 
 
Maboroshi
Guest
Posts: n/a
 
      10-24-2004
Hey Thank you works now

Cheers

Andrew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: What is the differences between tkinter in windows and Tkinter inthe other platform? Hidekazu IWAKI Python 0 12-15-2009 05:58 AM
What is the differences between tkinter in windows and Tkinter in theother platform? Hidekazu IWAKI Python 1 12-14-2009 03:44 PM
from Tkinter import *,win = Tk() "from Tkinter import *" Pierre Dagenais Python 0 08-03-2008 10:33 PM
Re: [Tkinter-discuss] Please help -- Tkinter Scale widget withDoubleVar is acting weird Jeff Epler Python 0 08-23-2004 02:31 PM
Re: [Tkinter-discuss] Please help -- Tkinter Scale widget withDoubleVar is acting weird Jeff Epler Python 0 08-20-2004 12:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57