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-
  1. from tkinter import *  
  2. main = Tk()  
  3. scrollbar = Scrollbar(main)  
  4. scrollbar.pack( side = RIGHT, fill=Y )  
  5. mylist = Listbox(main, yscrollcommand = scrollbar.set )  
  6. for line in range(100):  
  7.      mylist.insert(END, "C# corner " + str(line))  
  8. mylist.pack( side = LEFT, fill = BOTH )  
  9. scrollbar.config( command = mylist.yview )  
  10. main.mainloop()  
Output-
 
 Option Description
 activebackgroundIt sets the background color of widgets, when widget is under the cursor.
 bg It is used for normal background color.
bdIt 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.
Next » Tkinter Widget-Text