Tkinter

Scrollbar Tkinter | Python 3

In this tutorial, we are going to see how to use Scrollbar in Tkinter. The Scrollbar widget provides a slide controller that is used to add a scrollbar to widgets such as Listbox, Text and Canvas. Please note that you can make horizontal scrollbars on Entry widgets.
 


 
 

Syntax:

Here is the syntax to create this widget:

btn = Scrollbar ( master, option = value, ... )

 

Parameters:
  • master : This represents the parent window.
  • options : See below for a list of the most commonly used options for this widget. These options can be used as comma separated key-value pairs.

 

 

Example:
from tkinter import *

gui = Tk()

scrollbar = Scrollbar(gui)
scrollbar.pack( side = RIGHT, fill = Y )

liste = Listbox(gui, yscrollcommand = scrollbar.set )
for i in range(200):
   liste.insert(END, str(i) + " - Hello World!")

liste.pack(side = LEFT, fill = BOTH )
scrollbar.config(command = liste.yview )

gui.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *