faqts : Computers : Programming : Languages : Python : Snippets : Tkinter

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 6 people (83%) answered Yes
Recently 4 of 5 people (80%) answered Yes

Entry

Grid (possibly scrollable) in Tkinter?

Jul 5th, 2000 10:00
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 133, Greg McFarlane


"""
Packages: gui.tkinter
"""
"""
> ... Tkinter does not have a
> scrollable listbox. To make one isn't that hard...
You are correct in saying that it is easy to write a simply scrollable
listbox (see below *).
To this you may like to add things like a horizontal scrollbar (as
well as the vertical); dynamic display (only display the scrollbars
when necessary); convenient methods to populate the listbox; an
optional label; a margin between the scrollbar and the listbox; single
and double click callbacks; easy and consistent configurability of all
component options, etc.  You may then want to use all this as part of
a dropdown listbox (combobox).  If you want these features, it may
save you some pain to reuse an existing library, such as Pmw.
> ...Is building these things worthwile or shouldn't I bother
> and look into libraries like Pmw? For me, the ideal situation would be if I
> could distribute my programs without requiring external libraries.
If you are worried about having a dependency on Pmw, it is easy to
concatenate all of the Pmw modules you require into a single file and
include this with your software distribution.  A script to do this can
be found in bin/bundlepmw.py in the Pmw distribution at
<http://www.dscpl.com.au/pmw/>.
* Simple example of scrollable listbox:
"""
import Tkinter
l = Tkinter.Listbox()
l.pack(side = 'left', fill = 'both', expand = 1)
sb = Tkinter.Scrollbar(command = l.yview)
sb.pack(side = 'left', fill = 'y')
l.configure(yscrollcommand = sb.set)
l.mainloop()