Chapter 7. The Listbox Widget

A listbox widget is designed to list strings of text, one text string per line. You can then select a line or multiple lines from the listbox to perform other operations on. Some examples of things to place inside a listbox:

  • An alphabetized list of cities.

  • A list of servers to log in to. Select a server name and then enter a name and password into some entry widgets. Click the OK button to log in.

  • A list of operating systems.

  • A list of payment options: MasterCard, American Express, Visa, Check, Cash.

A listbox is ideal for replacing radiobuttons or checkboxes that have become too numerous to display on the screen. Usually 3 or 4 checkbuttons or radiobuttons aren't a big deal, but if you had to try to display 10 at a time, the window could get a little crowded. A group of radiobuttons can be replaced by a listbox that limits the number of selections to one and has a default selection. A bunch of checkbuttons can be replaced by a listbox that allows multiple selections.

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.