- 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
Which widget do you use for an Excel-like table in Tkinter?
Tkinter is a standard Python library that is used to build featured GUI-based desktop applications. Tkinter itself offers a variety of functions and widgets that can be used to design and serve the application's needs.
Tkinter Treeview widget is one of the consistent widgets which is used for driving the data and information in the form of a table. It works similar to MS Excel where we can add or define columns, insert some values to it, and perform queries in the backend using other Python libraries (such as Numpy or Pandas).
Tkinter Treeview widget is created by defining the Treeview(parent, column=(**col), **options) constructor. Now we can add columns and insert values to it.
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") # Add a Treeview widget tree= ttk.Treeview(win, column=("c1", "c2","c3"), show= 'headings') 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=('XYZ', 'ABC','123')) tree.pack() win.mainloop()
Output
Running the above code will display a table-like window with columns and entries for the row.
To Continue Learning Please Login
Login with Google