- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 display a Listbox with columns using Tkinter?
To deal with lots of data in any application, Tkinter provides a Treeview widget. It has various features such as displaying data in the form of tables consisting of Rows and Columns.
Treeview widget enables the user to add tables, insert data into it, and manipulate the data from the table. The Treeview widget can be constructed by defining the Treeview(parent, column, **options) constructor.
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") s = ttk.Style() s.theme_use('clam') # Add a Treeview widget tree = ttk.Treeview(win, column=("c1", "c2", "c3"), show='headings', height=5) tree.column("# 1", anchor=CENTER) tree.heading("# 1", text="ID") tree.column("# 2", anchor=CENTER) tree.heading("# 2", text="FName") tree.column("# 3", anchor=CENTER) tree.heading("# 3", text="LName") # Insert the data in Treeview widget tree.insert('', 'end', text="1", values=('1', 'Joe', 'Nash')) tree.insert('', 'end', text="2", values=('2', 'Emily', 'Mackmohan')) tree.insert('', 'end', text="3", values=('3', 'Estilla', 'Roffe')) tree.insert('', 'end', text="4", values=('4', 'Percy', 'Andrews')) tree.insert('', 'end', text="5", values=('5', 'Stephan', 'Heyward')) tree.pack() win.mainloop()
Output
When we execute the above code, it will display a List of items with some columns.
- Related Articles
- How to clear a Tkinter ListBox?
- How to edit a Listbox item in Tkinter?
- Creating scrollable Listbox within a grid using Tkinter
- How to fit Tkinter listbox to contents?
- How to keep selections highlighted in a Tkinter Listbox?
- How to fully change the color of a Tkinter Listbox?
- How to directly modify a specific item in a TKinter listbox?
- How to remove multiple selected items in the listbox in Tkinter?
- How to select at the same time from two Tkinter Listbox?
- How to display MySQL Table Name with columns?
- Attach scrollbar to listbox as opposed to window in Tkinter
- Is it possible to color a specific item in a Tkinter Listbox widget?
- Default to and select the first item in Tkinter Listbox
- How can I change the text of the Tkinter Listbox item?
- Java Program to display table with columns in the output using Formatter

Advertisements