From: Anthony Papillion on
So I'm trying to add a Listbox to my window. I want it to be the width
of my window and the height of my window. I'm using the following
code ('root' is my toplevel window):

gsItems = Listbox(root, width=root.winfo_width(),
height=root.winfo_height())
gsItems.pack()

While you would think this code would set the height and width of
gsItems to the height and width of root, it doesn't. Instead it puts a
little tiny listbox in the middle of the form.

I've been Googling for almost an hour. Can anyone help me figure this
out? Point me in the right direction?

Thanks!
Anthony
From: eb303 on
On Jun 21, 7:36 am, Anthony Papillion <papill...(a)gmail.com> wrote:
> So I'm trying to add a Listbox to my window. I want it to be the width
> of my window and the height of my window.  I'm using the following
> code ('root' is my toplevel window):
>
> gsItems = Listbox(root, width=root.winfo_width(),
> height=root.winfo_height())
> gsItems.pack()
>
> While you would think this code would set the height and width of
> gsItems to the height and width of root, it doesn't. Instead it puts a
> little tiny listbox in the middle of the form.
>
> I've been Googling for almost an hour. Can anyone help me figure this
> out? Point me in the right direction?
>
> Thanks!
> Anthony

The problem you have in your script is probably simple: at the time
when you put the listbox in it, the windows still contains nothing, or
very little. And what you're doing is to take its _current_ size and
assign it to the listbox. So the listbox will be very small, since at
the time you ask for its dimensions, the window itself is very small.

Basically, you're taking the wrong approach there: you should put the
listbox in the window telling it to adapt its size to its parent
container, and then resize the window if you want to.

The first step is done via the geometry manager, which can be pack or
grid. Please refer to your documentation to know how to use them to
make a widget adapt its size to its container. The documentation I use
myself is the plain tcl/tk documentation, that you can find at
http://www.tcl.tk/man/tcl8.5/contents.htm. The documentation for pack
is at http://www.tcl.tk/man/tcl8.5/TkCmd/pack.htm and the one for grid
at http://www.tcl.tk/man/tcl8.5/TkCmd/grid.htm. Please note this
documentation might not be suitable for you, as it is not a Python/
Tkinter documentation.

The second step can be done with the method called geometry on your
window. The size you want should then be specified as a string
'<width>x<height>'.

Here is an example, using the pack geometry manager:

from Tkinter import *
root = Tk()
gsItems = Listbox(root)
gsItems.pack(fill=BOTH, expand=TRUE)
root.geometry('400x300')
root.mainloop()

HTH
- Eric -
From: rantingrick on
On Jun 21, 12:36 am, Anthony Papillion <papill...(a)gmail.com> wrote:
> So I'm trying to add a Listbox to my window. I want it to be the width
> of my window and the height of my window.  I'm using the following
> code ('root' is my toplevel window):
>
> gsItems = Listbox(root, width=root.winfo_width(),
> height=root.winfo_height())
> gsItems.pack()
>
> While you would think this code would set the height and width of
> gsItems to the height and width of root, it doesn't. Instead it puts a
> little tiny listbox in the middle of the form.


eb303 answered your question perfectly however he failed to point you
toward the proper documentation. The Python docs you need are here...

http://effbot.org/tkinterbook/

<FYI> Remember Guys, this is a Python mailing list. Always give
reference FIRST to docs that are "Python" specific. *Then* if you want
to show off your multi lingual-ness by all means post extra links. </
FYI>
From: Anthony Papillion on
Thank you, RantingRick and EB303. Much appreciated and it looks like
it works fine now. Still learning but I am amazed every single day how
simple Python is!

Thanks Again,
Anthony Papillion
From: eb303 on
On Jun 21, 6:36 pm, rantingrick <rantingr...(a)gmail.com> wrote:
> On Jun 21, 12:36 am, Anthony Papillion <papill...(a)gmail.com> wrote:
>
> > So I'm trying to add a Listbox to my window. I want it to be the width
> > of my window and the height of my window.  I'm using the following
> > code ('root' is my toplevel window):
>
> > gsItems = Listbox(root, width=root.winfo_width(),
> > height=root.winfo_height())
> > gsItems.pack()
>
> > While you would think this code would set the height and width of
> > gsItems to the height and width of root, it doesn't. Instead it puts a
> > little tiny listbox in the middle of the form.
>
> eb303 answered your question perfectly however he failed to point you
> toward the proper documentation. The Python docs you need are here...
>
>    http://effbot.org/tkinterbook/
>
> <FYI> Remember Guys, this is a Python mailing list. Always give
> reference FIRST to docs that are "Python" specific. *Then* if you want
> to show off your multi lingual-ness by all means post extra links. </
> FYI>

Thanks for the condescendent tone in your post. And FYI, remember that
this is not Microsoft Support here: people are helping freely and
because they want to, so they might not have the time to look for
documentation they just don't have at hand, because they never use it.
If you want to provide pointers to better stuff, you're welcome. Your
unpleasant remarks are not.

Go on like this and you'll just discourage everyone to give some of
their time to help people.