- 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
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.
- Related Articles
- How to open an Excel Spreadsheet in Treeview widget in Tkinter?
- How do you check if a widget has a focus in Tkinter?
- How to use a StringVar object in an Entry widget in Tkinter?
- How to use the Entry widget in Tkinter?
- How to set focus for Tkinter widget?
- How to disable an Entry widget in Tkinter?
- Notebook widget in Tkinter
- How do I get an event callback when a Tkinter Entry widget is modified?
- How do you use ‘foreach’ loop for iterating over an array in C#?
- How do I center the text in a Tkinter Text widget?
- How do you use Vernier caliper for an accurate measurement of distance?
- Python Tkinter – How to display a table editor in a text widget?
- Creating a table look-a-like using Tkinter
- Progressbar widget in Python Tkinter
- How to interactively validate an Entry widget content in tkinter?
