[Tutor] resizing Tkinter widgets

Lance E Sloan lsloan@umich.edu
Fri, 01 Feb 2002 12:22:32 -0500


It's been a while since I've posted to this list, but I've been
lurking and reading.  I've got a Tkinter question and if it would
be better addressed to some other mailing list, like a Tkinter
one, please let me know.

I'm new to Tkinter and GUI programming in general.  I'm having
trouble figuring out how to make my Listbox and Scrollbar widgets
grow and shrink when the Tk window is resized.  Here's some
code that I've been monkeying with, trying to make this work:

	from Tkinter import *

	master = Tk()
	master.config(bg="green")

	frame = Frame(master, bg="blue")
	scrollbar = Scrollbar(frame, orient=VERTICAL)
	listbox = Listbox(frame, yscrollcommand=scrollbar.set, bg="red")
	scrollbar.config(command=listbox.yview)
	scrollbar.pack(side=RIGHT, fill=Y)
	listbox.pack(side=LEFT, fill=BOTH, expand=1)

	listbox.insert(END, 'abc')

	frame.pack()

	master.mainloop()

This is based on Lundh's Tkinter documentation about Listbox.  I've
added colors to the root Tk window, Frame, and Listbox so that
I could see what was growing when I resized the window.  At first,
I thought the Frame enclosing the Listbox was growing, but by adding
the colors, I can see that it's actually just the green root window
growing.

Suggestions?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Python & Perl CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"