Tkinter Widgets-Listbox
Listbox widgets are used to display list of options to the user and select one option to perform a function, according to the selection.
Syntax-
w = Listbox ( main,option)
Parameter-
Main- parent Window.
Option- attribute of button widget.
Example-
Example-
- from tkinter import *
- import tkinter
- top = Tk()
- Lb1 = Listbox(top)
- Lb1.insert(1, "Python")
- Lb1.insert(2, "Perl")
- Lb1.insert(3, "C")
- Lb1.insert(4, "PHP")
- Lb1.insert(5, "JSP")
- Lb1.insert(6, "Ruby")
- Lb1.pack()
- top.mainloop()
Output-
Option | Description |
bg | Normal background color. |
bd | Sets Border width in pixels. Default is 2. |
cursor | Cursor is used to create a cursor in canvas like arrow, circle, dot etc. |
font | It is used to set font of the text. |
fg | It sets normal foreground (text) color of widgets. |
height | It is used to set the height of widgets. |
highlightcolor | It changes the color of widgets on focus. |
highlightthickness | It is used to set thickness of the focus highlight. |
relief | Relief is special type of border. The values are SUNKEN, RAISED, GROOVE, and RIDGE. |
selectbackground | It is used to set the background color of the selected text. |
selectmode | It is used to set the selection mode like BROWSE,SINGLE,MULTIPLE,EXTENDED. |
width | It is used to set the width of widgets. |
xscrollcommand | It is used to scroll on the defined value in x direction. |
yscrollcommand | It is used to define the scrolling value in y direction |
Summary
In this chapter, you learnt what listbox widget is and how to use the property of the widget.