an added bonus, it supports both window and frame-style menus, so it can be used by
both standalone programs and nested components. Although it’s important to know
the underlying calls used to make menus, you don’t necessarily have to remember them
for long.
Listboxes and Scrollbars
Let’s rejoin our widget tour. Listbox widgets allow you to display a list of items for
selection, and Scrollbars are designed for navigating through the contents of other
widgets. Because it is common to use these widgets together, we’ll study them both at
once. Example 9-9 builds both a Listbox and a Scrollbar, as a packaged set.
Example 9-9. PP4E\Gui\Tour\scrolledlist.py
"a simple customizable scrolled listbox component"
from tkinter import *
class ScrolledList(Frame):
def init(self, options, parent=None):
Frame.init(self, parent)
self.pack(expand=YES, fill=BOTH) # make me expandable
self.makeWidgets(options)
def handleList(self, event):
index = self.listbox.curselection() # on list double-click
label = self.listbox.get(index) # fetch selection text
self.runCommand(label) # and call action here
or get(ACTIVE)
def makeWidgets(self, options):
sbar = Scrollbar(self)
Figure 9-13. menuDemo3: unresized GIF images in the toolbar
522 | Chapter 9: A tkinter Tour, Part 2