I have two questions on the python code at the bottom:
.
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()
For item 1, you need to call self.master.rowconfigure(0, weight=1)
and set sticky="nsew"
in self.tree.grid(...)
.
For item 2, add stretch=0
to self.tree.column('x', ...)
and self.tree.column('y', ...)
Updated code:
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.rowconfigure(0, weight=1) # added
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, stretch=0) # added stretch=0
self.tree.column('y', width=40, stretch=0) # added stretch=0
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, sticky="nsew") # added sticky="nsew"
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()