- 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
How to attach a vertical scrollbar to a Treeview using Tkinter?
If you want to display a list of items that contains some columns in it, then you can use the Treeview widget in Tkinter. The Treeview widget allows the user to add a large number of lists along with the properties that can be customized instantly.
If you want to attach a vertical scrollbar to the list of items in a Treeview widget, then you can define a constructor of Scrollbar and configure it by adding the command to it. Let’s take an example and see how it works.
Example
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win= Tk() # Set the size of the tkinter window win.geometry("700x350") # Create an instance of Style widget style= ttk.Style() style.theme_use('clam') # Add a Treeview widget and set the selection mode tree= ttk.Treeview(win, column=("c1", "c2"), show='headings', height= 8, selectmode="browse") tree.column("#1", anchor=CENTER, stretch= NO) tree.heading("#1", text="Fname") tree.column("#2", anchor=CENTER, stretch=NO) tree.heading("#2", text="Lname") # Insert the data in Treeview widget tree.insert('', 'end', text= "1",values=('Alex', 'M')) tree.insert('', 'end', text="2",values=('Belinda','Cross')) tree.insert('', 'end', text="3",values=('Ravi','Malviya')) tree.insert('', 'end', text="4",values=('Suresh','Rao')) tree.insert('', 'end', text="5",values=('Amit','Fernandiz')) tree.insert('', 'end', text= "6",values=('Raghu','Sharma')) tree.insert('', 'end',text= "7",values=('David','Nash')) tree.insert('', 'end',text= "8",values=('Ethan','Plum')) tree.insert('', 'end', text= "9", values=('Janiece','-')) # Adding a vertical scrollbar to Treeview widget treeScroll = ttk.Scrollbar(win) treeScroll.configure(command=tree.yview) tree.configure(yscrollcommand=treeScroll.set) treeScroll.pack(side= RIGHT, fill= BOTH) tree.pack() win.mainloop()
Output
Running the above code will display a window that contains a list of items in a treeview widget along with a vertical scrollbar attached to it.
- Related Articles
- How to attach a vertical scrollbar in Tkinter text widget?
- How to attach a Scrollbar to a Text widget in Tkinter?
- Attach scrollbar to listbox as opposed to window in Tkinter
- How to add a column to a Tkinter TreeView widget?
- How to get a horizontal scrollbar in Tkinter?
- How to create a TreeView using JavaFX?
- How to change the background color of a Treeview in Tkinter?
- How to clear an entire Treeview with Tkinter?
- How to disable multiselection on Treeview in tkinter?
- How to create a ScrollBar using JavaFX?
- Adding a scrollbar to a group of widgets in Tkinter
- Changing the appearance of a Scrollbar in Tkinter (using ttk styles)
- How to create a responsive custom scrollbar using CSS?
- How to open an Excel Spreadsheet in Treeview widget in Tkinter?
- Tkinter scrollbar for frame

Advertisements