- Trending Categories
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
Attach scrollbar to listbox as opposed to window in Tkinter
A Listbox widget contains a list of items such as a list of numbers or characters. Let us suppose that you want to create a long list of items using the Listbox widget. Then, there should be a proper way to view all the items in the list. Adding Scrollbar to the list box widget will be helpful in this case.
To add a new scrollbar, you have to use Listbox(parent, bg, fg, width, height, bd, **options) constructor. Once the Listbox is created, you can add a scrollbar to it by creating an object of Scrollbar(**options).
Example
#Import the required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter Frame win = Tk() #Set the geometry of Tkinter Frame win.geometry("700x350") #Create a vertical scrollbar scrollbar= ttk.Scrollbar(win, orient= 'vertical') scrollbar.pack(side= RIGHT, fill= BOTH) #Add a Listbox Widget listbox = Listbox(win, width= 350, bg= 'bisque') listbox.pack(side= LEFT, fill= BOTH) for values in range(100): listbox.insert(END, values) listbox.config(yscrollcommand= scrollbar.set) #Configure the scrollbar scrollbar.config(command= listbox.yview) win.mainloop()
Output
Running the above code will display a window that contains a Listbox widget with several items in it. The Vertical scrollbar is attached to the Listbox widget.
- Related Articles
- How to attach a vertical scrollbar in Tkinter text widget?
- How to attach a Scrollbar to a Text widget in Tkinter?
- How to attach a vertical scrollbar to a Treeview using Tkinter?
- Resize the Tkinter Listbox widget when the window resizes
- How to clear a Tkinter ListBox?
- How to fit Tkinter listbox to contents?
- How to edit a Listbox item in Tkinter?
- How to get a horizontal scrollbar in Tkinter?
- How to keep selections highlighted in a Tkinter Listbox?
- Tkinter scrollbar for frame
- Default to and select the first item in Tkinter Listbox
- Initialize a window as maximized in Tkinter Python
- How to display a Listbox with columns using Tkinter?
- How to remove multiple selected items in the listbox in Tkinter?
- Adding a scrollbar to a group of widgets in Tkinter

Advertisements