Tkinter Widget-Scrollbar
This widget is used to create a vertical and horizontal scrollbar.
Syntax-
w = Scrollbar (main, option)
Parameter-
Main- parent Window.
Option- attribute of button widget.
Example-
- from tkinter import *
- main = Tk()
- scrollbar = Scrollbar(main)
- scrollbar.pack( side = RIGHT, fill=Y )
- mylist = Listbox(main, yscrollcommand = scrollbar.set )
- for line in range(100):
- mylist.insert(END, "C# corner " + str(line))
- mylist.pack( side = LEFT, fill = BOTH )
- scrollbar.config( command = mylist.yview )
- main.mainloop()
Output-
Option | Description |
activebackground | It sets the background color of widgets, when widget is under the cursor. |
bg | It is used for normal background color. |
bd | It sets border width in pixels. Default is 2. |
command | It is used to call the method or function. |
cursor | Cursor is used to create a cursor in widgets like arrow, circle, dot etc. |
elementborderwidth | It is used to define an element border width. |
highlightbackground | It is used to highlight background color. |
highlightcolor | It changes color of widgets on focus. |
highlightthickness | It is used to define highlight thickness. |
jump | This option controls what happens when a user drags the slider. Normally (jump=0), every small drag of the slider causes the command callback to be called. If you set this option to 1, the callback isn't called until the user releases the mouse button. |
orient | It is used to set the orientation of a scrollbar. |
repeatdelay | It is used to define repeat delay. |
takefocus | It is used to define the focus behaviour. |
Troughcolorused | It is used to define the color of the trough. |
width | It is used to define the width of widgets. |
Summary
In this chapter, you learnt what scrollbar widget is and how to use the property of the widget.