I have a Frame that contains Treeview and a Frame-embedded-in-a-Canvas. Treeview displays documents from MongoDB in one '#0'<\/code> column and every time a user selects any document I generate from document's fields a list of Checkbuttons in the Frame-embedded-in-a-Canvas.
Every time after generating new Checkbuttons list my Treeview width grows by 30 pixels without any regard to the fact that both the Treeview and the Frame-embedded-in-a-Canvas are expected to be in parent's grid columns 0 and 1 respectively with zero weight.
And below you can find my code concerning these widgets.
def treeview_reload():
dt_tv.delete(*dt_tv.get_children())
dt_tv.insert('', 'end', '_b_', text='biomes')
dt_tv.insert('', 'end', '_z_', text='zones')
dt_tv.insert('', 'end', '_p_', text='points')
dt_tv.insert('', 'end', '_m_', text='biomaterials')
dt_tv.insert('', 'end', '_c_', text='characters')
def tv_sel_handler(event):
try:
sel_iid = event.widget.selection()[0]
except IndexError:
sel_iid = ''
try:
generate_model(MAP[sel_iid])
except KeyError:
pass
def generate_model(document, new_list=True, row=0, indent=0):
if new_list:
for c in list(dt_model.children.values()):
c.destroy()
i = row
for field in document.keys():
if type(document[field]) is list:
cb = ttk.Label(dt_model, text=indent*2*' '+field)
cb.grid(row=i, column=0, sticky='w', padx=30, pady=4)
cb['font'] = ("Noto Mono", 13)
pass
elif type(document[field]) is dict:
cb = ttk.Checkbutton(dt_model, text=indent*2*' '+field)
cb.grid(row=i, column=0, sticky='w')
ttk.Style().configure('Mono.TCheckbutton', font=("Noto Mono", 13))
cb['style'] = 'Mono.TCheckbutton'
i = generate_model(document[field], False, i+1, indent+1)
else:
cb = ttk.Checkbutton(dt_model, text=indent*2*' '+field)
cb.grid(row=i, column=0, sticky='w')
ttk.Style().configure('Mono.TCheckbutton', font=("Noto Mono", 13))
cb['style'] = 'Mono.TCheckbutton'
i += 1
if i > 17:
vsb = ttk.Scrollbar(pdb_data, orient=VERTICAL, command=dt_canv.yview)
dt_canv['yscrollcommand'] = vsb.set
vsb.grid(row=0, column=2, sticky='nsw')
dt_model.bind('<Configure>',
lambda event, canvas=dt_canv:
canvas.configure(scrollregion=canvas.bbox("all")))
dt_model.bind('<Enter>',
lambda event:
dt_canv.bind_all("<MouseWheel>",
lambda event:
dt_canv.yview_scroll(int(-1*(event.delta/120)), "units")))
dt_model.bind('<Leave>',
lambda event: dt_canv.unbind_all("<MouseWheel>"))
return i
# ...
# ___ frame for the data
pdb_data = ttk.Frame(page_db, width=1250, height=450)
pdb_data.grid(row=6, column=0, columnspan=2, sticky='nsew', pady=24)
# ____ categorized documents list
dt_tv = ttk.Treeview(pdb_data, selectmode='browse', show=('tree',))
dt_tv.column('#0', width=250)
dt_tv.grid(row=0, column=0, sticky='nsw')
dt_tv.bind('<<TreeviewSelect>>', tv_sel_handler)
treeview_reload()
# ____ auxiliary canvas
dt_canv = Canvas(pdb_data, borderwidth=0, width=300)
dt_canv.grid(row=0, column=1, sticky='nsw', padx=10)
# _____ frame-embedded-in-a-canvas for checkbuttons list
dt_model = ttk.Frame(dt_canv, width=400, height=450)
dt_canv.create_window((0,0), window=dt_model, anchor='nw')
pdb_data.rowconfigure(0, weight=1)
root.mainloop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.