Creating a multiple Selection using Tkinter
Tkinter is a GUI library in python which is easy to read and understand. In Tkinter, multiple selections can be done using the List box widget. Generally, a Listbox displays different items in the form of a list. A list box widget provides one or more selections of items from a list. There are many options available in a Listbox widget that makes the user select multiple options. By assigning the select mode option as multiple, the user can able to select multiple options. If the select mode option is single then only one option can be selected by the user.
The selectmode option of a listbox widget can be single, browse, multiple or extended.
- single – Selects one line of text.
- browse – It is a default option where the user can select one line of text.
- multiple – Selects multiple lines of text without dragging from first line of option to last line.
- extended – User can select and drag adjacent multiple lines of text.
list_box = Listbox(root, options, ....)
Example 1: Python program displaying limited items in the listbox.
From the above multiple selection Listbox, the user can select multiple options. As there are limited items in the Listbox that fit into the prescribed size, the user can able to see all the items. But if there are more items to be displayed to the user then all the items are not visible at once in a Listbox. Hence, attaching a scrollbar to a Listbox is necessary if there are more items to be displayed in a list. This can be done by the
yscrollcommand option(to scroll vertically) in Listbox.
Example 2: Python program displaying List box with attached scroll bar.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course