- 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 disable multiselection on Treeview in tkinter?
The Treeview widget is used to display a list of items with more than one feature in the form of columns. By default, the listed items in a Treeview widget can be selected multiple times, however you can disable this feature by using selectmode="browse" in the Treeview widget constructor. The Treeview widget can be implemented by using the Treeview(root, column, **options) constructor.
Example
The following example demonstrates how to disable multiselection in a Treeview widget.
# 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("700x300") # 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= "5",values=('Raghu','Sharma')) tree.insert('', 'end',text= "5",values=('David','Nash')) tree.insert('', 'end',text= "5",values=( 'Ethan','Plum')) tree.pack() win.mainloop()
Output
Running the above code will display a treeview widget with a list of items. You can select only a single item at a time from the list.
- Related Articles
- How to clear an entire Treeview with Tkinter?
- How to open an Excel Spreadsheet in Treeview widget in Tkinter?
- How to add a column to a Tkinter TreeView widget?
- How to change the background color of a Treeview in Tkinter?
- How to disable a Combobox in Tkinter?
- Delete and Edit items in Tkinter TreeView
- How to attach a vertical scrollbar to a Treeview using Tkinter?
- How can I set the row height in Tkinter TreeView?
- How to correctly select multiple items with the mouse in Tkinter Treeview?
- How to Disable / Enable a Button in TKinter?
- How to disable an Entry widget in Tkinter?
- How to disable checkbutton Tkinter (grey out)?
- How to disable (grey out) a checkbutton in Tkinter?
- How to gray out (disable) a Tkinter Frame?
- How to hide or disable the mouse pointer in Tkinter?

Advertisements