I have two questions on the python code at the bottom:
- I would like that the CheckboxTreeview widget covers as much height as there is available. If the user resizes the window, the should be more lines in the widget. I know about the height parameter, but this gives me always a fixed amount of rows. How can I modify the code to my needs?
- I would like the two columns x and y to have the fixed width as written in the code. If I resize the window, the width of these columns is also modified. Furthermore, is it somehow that the x-scrollbar is effective and can be used if the text in the first column is too long?
.
import tkinter as tk
from tkinter import ttk
from ttkwidgets import CheckboxTreeview
class App():
def __init__(self, master):
self.master = master
self.master.geometry('300x400')
self.master.columnconfigure(0, weight=1)
self.tree = CheckboxTreeview(self.master)
xsb = ttk.Scrollbar(self.master, orient='horizontal', command=self.tree.xview)
ysb = ttk.Scrollbar(self.master, orient='vertical', command=self.tree.yview)
self.tree.configure(yscroll=ysb.set)
self.tree['columns']=('x', 'y')
self.tree.column('x', anchor='e', width=40)
self.tree.column('y', width=40)
self.tree.heading('#0', text='abc', anchor='w')
self.tree.heading('x', text='x', anchor='w')
self.tree.heading('y', text='y', anchor='w')
self.tree.grid(row=0, column=0)
ysb.grid(row=0, column=1, sticky='ns')
xsb.grid(row=1, column=0, sticky='ew')
self.master.frame = tk.Frame(self.master, highlightbackground="black", highlightthickness=2)#, background='#ff0')
self.master.frame.grid(row=4, column=0, columnspan=2, sticky='w')
tk.Label(self.master.frame, text='TEXT', font=tk.font.Font(size=16, weight='bold')).grid(row=0, column=0)
self.tree.insert('', 'end', text='node 1', values=('x1', 'y1'), open=True)
self.tree.insert('', 'end', text='node 2 - this is a very long text which should be scrollable', values=('x2', 'y2'), open=True)
root = tk.Tk()
app = App(root)
app.master.mainloop()
New contributor
bene is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.