15-10. Listbox widget

The ListBox widget is utilized for showcasing various items, all of which must adhere to the same font style and color. These items are expected to be of Text type. Users have the flexibility to select one or multiple items from the list based on their needs.

For example,

Output:

A listbox is displayed containing the items Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.

A ListBox widget enables users to select one or more items from a list. It offers various options to facilitate multiple selections. By setting the selectmode option to "multiple", users can select multiple items. Conversely, if selectmode is set to "single", only one item can be selected at a time.

The selectmode option of a Listbox widget can take on four values:

  • single: Allows selection of a single line of text
  • browse: The default option, permitting selection of one line of text
  • multiple: Enables selection of multiple lines of text without the need for dragging from the first line to the last
  • extended: Users can select and drag adjacent multiple lines of text

For example, 

Output:

A listbox is displayed containing the items Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday. Monday, Tuesday and Wednesday are selected.

Additionally, vertical and horizontal scrollbars can be incorporated into the listbox widget.

Output:

A listbox is displayed containing the following items, and a horizontal scrollbar is visible: “Blue whales have an average weight of 110 tons and an average length of 24 meters.” “North Pacific right whale have an average weight of 60 tons and an average length of 15.5 meters.” “Southern right whales have an average weight of 58 tons and an average length of 15.25 meters.” “Fin whales have an average weight of 57 tons and an average length of 19.5 meters.” “Bowhead whales have an average weight of 54.5 tons and an average length of 15 meters.”