

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 change ttk.Treeview column width and weight in Python 3.3?
To display a large set of data in a Tkinter application, we can use the Treeview widget. Generally, we represent data through tables that contain a set of rows and columns. We can add the data in the form of a table with the help of the Treeview widget.
To configure the column width of the Treeview widget, we can use the width and stretch property. It sets the width of the Treeview widget column with the given value.
Example
In this example, we have created a table that contains a list of programming languages. The width of columns ‘ID’ and ‘Programming Language’ is set to their content. Further, we can give a value to set the width of the columns.
# 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 tree=ttk.Treeview(win, column=("c1", "c2"), show='headings', height=8) tree.column("# 1",anchor=CENTER, stretch=NO, width=100) tree.heading("# 1", text="ID") tree.column("# 2", anchor=CENTER, stretch=NO) tree.heading("# 2", text="Programming Language") # Insert the data in Treeview widget tree.insert('', 'end',text="1",values=('1','C++')) tree.insert('', 'end',text="2",values=('2', 'Java')) tree.insert('', 'end',text="3",values=('3', 'Python')) tree.insert('', 'end',text="4",values=('4', 'Golang')) tree.insert('', 'end',text="5",values=('5', 'JavaScript')) tree.insert('', 'end',text="6",values=('6', 'C# ')) tree.insert('', 'end',text="7",values=('6', 'Rust')) tree.insert('', 'end',text="8",values=('6', 'SQL')) tree.pack() win.mainloop()
Output
Run the above code to display a Table that contains a list of programming languages and Index.
- Related Questions & Answers
- How to edit the style of a heading in Treeview (Python ttk)?
- 3 and 7 in Python
- How to align text to the right in ttk Treeview widget?
- Base 3 to integer in Python
- How to create python namespace packages in Python 3?
- 3-6-9 in Python
- How does == operator works in Python 3?
- Understanding Code Reuse and Modularity in Python 3
- How to create a 3-column layout grid with CSS?
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++
- Integer to Base 3 Number in Python
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Differences between Python 2.x and Python 3.x?
- Filling diagonal to make the sum of every row, column and diagonal equal of 3×3 matrix using c++
- How to apply a 3×3 convolution matrix using imageconvolution() in PHP?
Advertisements