Home > database >  Is there a way to shrink the column width of the drop-down widgets in tkinter ttk Treeview?
Is there a way to shrink the column width of the drop-down widgets in tkinter ttk Treeview?

Time:10-28

enter image description here

When I create a treeview with children, it has these widgets to click in the left most column to expand/hide parents. Once I run the program I am able to click and drag to resize this column smaller, but I cannot figure out how to resize it in code.

I honestly haven't tried much because I don't even know where to start, I don't know of any way to modify this widget column at all. `

# Standard Library
import tkinter as tk
from tkinter import ttk


root = tk.Tk()

# creating treeview
columns = ('Category', 'Parameter', 'Value', 'Unit', 'Status')
tree = ttk.Treeview(root, columns=columns)
tree.pack(side='left')

tree.column('Category', minwidth=0, width=110, stretch=True)
tree.column('Parameter', minwidth=0, width=150, stretch=True)
tree.column('Value', minwidth=0, width=110, stretch=True)
tree.column('Unit', minwidth=0, width=110, stretch=True)
tree.column('Status', minwidth=0, width=110, stretch=True)

tree.heading('Category', text='Category')
tree.heading('Parameter', text='Parameter')
tree.heading('Value', text='Value')
tree.heading('Unit', text='Unit')
tree.heading('Status', text='Status')

info = ("one", "two", "three", "four", "five")
tree.insert("", tk.END, iid=1, values=info, open=False)
tree.insert("", tk.END, iid=2, values=info, open=False)
tree.move(2, 1, 0)

root.title("Test File Editor")
root.geometry("850x700")
root.mainloop()

`

CodePudding user response:

That column can be identified with the name "#0". You can configure the width of that column like any other column, with the column method.

tree.column('#0', width=10)
  • Related