Tkinter #11: Scroll bar in Tkinter

 Scroll bar in Tkinter

For connecting the scrollbar to a widget follow the following two steps.
1. To set the Scrollbar widget using syntax
     a = Scrollbar(master , options)

2.  To add the command  
     widget(yscrollcommand=name_of_scrollbar.set)  
     in the widget option
    example:
    lis = Text(root,yscrollcommand = a.set)
  lis.pack()

2. To apply following condition in the name of scrollbar
    name_of_Scrollbar.config(command=widget.yview)
    a.config(command = lis.yview)


Example Through code is following
*********************************************************
from tkinter import *
root = Tk()
# To add scrollbar to any widget following three steps are necessary

# 1.) First rule is to set a scroll bar widget
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT,fill=Y)
# 2.) Second rule is to add 'yscrollcommand = scrollbar.set' option in the widget in
# which we want to add the scrollbar as shown below.
lis = Text(root,yscrollcommand=scrollbar.set)
lis.pack()
# 3.) Third rule is to typee 'scrollbar.config(command = name_of_widget.yview)'
scrollbar.config(command = lis.yview)
*********************************************************

Comments

Popular posts from this blog

#2 Library Management Software

#3 Water remainder Programme