Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change ttk.Treeview column width and weight in Python 3.3

I have created a GUI for my application with Tkinter. I am using also a treeview widget. However I am unable to change its column widths and weights. How to do it properly?

Sample:

tree = Treeview(frames[-1],selectmode="extended",columns=("A","B"))
tree.heading("#0", text="C/C++ compiler")
tree.column("#0",minwidth=0,width=100)

tree.heading("A", text="A")   
tree.column("A",minwidth=0,width=200) 

tree.heading("B", text="B")   
tree.column("B",minwidth=0,width=300) 

As far as I understand it should create three columns with widths: 100,200 and 300. However nothing like that happens.

like image 741
Misery Avatar asked May 04 '13 16:05

Misery


1 Answers

Treeview.Column does not have weight option, but you can set stretch option to False to prevent column resizing.

from tkinter import *
from tkinter.ttk import *


root = Tk()
tree = Treeview(root, selectmode="extended", columns=("A", "B"))
tree.pack(expand=YES, fill=BOTH)
tree.heading("#0", text="C/C++ compiler")
tree.column("#0", minwidth=0, width=100, stretch=NO)
tree.heading("A", text="A")
tree.column("A", minwidth=0, width=200, stretch=NO) 
tree.heading("B", text="B")
tree.column("B", minwidth=0, width=300)
root.mainloop()
like image 63
kalgasnik Avatar answered Sep 18 '22 12:09

kalgasnik