- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Adding a scrollbar to a group of widgets in Tkinter
Let’s suppose you want to add a scrollbar to a group of widgets in an application, then you can use the Scrollbars property in tkinter. Adding Scrollbars to a group of widgets can be achieved by Scrollbar(....options).
Example
In this example, we will define a group of Listbox widgets and then add a vertical scrollbar to make the list scrollable.
#Import the required library from tkinter import * #Create an instance of tkinter frame or window win = Tk() #Define the geometry win.geometry("750x400") #Create a listbox listbox= Listbox(win) listbox.pack(side =LEFT, fill = BOTH) #Create a Scrollbar scrollbar = Scrollbar(win) scrollbar.pack(side = RIGHT, fill = BOTH) #Insert Values in listbox for i in range(150): listbox.insert(END, i) listbox.config(yscrollcommand = scrollbar.set) scrollbar.config(command = listbox.yview) win.mainloop()
Output
Running the above code will display a window that contains a list of numbers in the range 1-150. The list of numbers is bound with a vertical scrollbar which makes the list vertically scrollable.
Advertisements