'canvas.bind() - Configure width not working (Frame doesn't fill canvas)
I've just managed to configure a scrollbar to properly scroll these widgets, but I'm still having an issue with the frame not fitting the canvas.
I have a bunch of labels that fill out a frame, but the frame doesn't stretch to fill the canvas in the way I want it to.
There was a solution to this on another question that suggested using .bind() and '<Configure' (see code) to have the canvas resized to fit the frame (I think), but there are two problems with that:
It's not working.
I want the frame to stretch to the canvas, not the canvas to shrink to the frame.
Any and all help is greatly appreciated. Pictures and relevant code below.
Thank you!
def list_talent():
global new_button, map_button, scrollbar, results_canvas, active_tab, results_frame
results_canvas.destroy()
scrollbar.destroy()
new_button.destroy()
map_button.destroy()
results_frame.destroy()
active_tab = ''
results_canvas = Canvas(root, width=1080)
results_canvas.grid(row=4, column=0, columnspan=7)
scrollbar = ttk.Scrollbar(root, orient=VERTICAL, command=results_canvas.yview)
scrollbar.grid(row=4, column=8, sticky=N+S)
results_frame = Frame(results_canvas)
results_frame_id = results_canvas.create_window((0, 0), window=results_frame, anchor="nw")
def frame_width(event):
canvas_width = event.width
results_canvas.itemconfig(results_frame_id, width=canvas_width)
results_canvas.bind('<Configure>', frame_width)
new_button = Button(root, text='New', font=('Times New Roman', 12), command=new_record)
new_button.grid(row=5, column=0)
map_button = Button(root, text='Map', font=('Times New Roman', 12))
map_button.grid(row=5, column=7)
results_title = ['ID', 'Name', 'Profession', 'City', 'Date Signed', 'Phone Number', 'Quick Note']
for index, text in enumerate(results_title):
res_title_label = Label(results_frame, text=text)
res_title_label.grid(row=0, column=index)
mycursor.execute("SELECT * FROM talents")
result = mycursor.fetchall()
for index, x in enumerate(result):
results_label = Label(results_frame, text=x[10])
results_label.grid(row=1+index, column=0, padx=10)
results_label = Label(results_frame, text=x[0])
results_label.grid(row=1+index, column=1, padx=10)
results_label = Label(results_frame, text=x[2])
results_label.grid(row=1+index, column=2, padx=10)
results_label = Label(results_frame, text=x[7])
results_label.grid(row=1+index, column=3, padx=10)
results_label = Label(results_frame, text=x[11])
results_label.grid(row=1+index, column=4, padx=10)
results_label = Label(results_frame, text=x[2])
results_label.grid(row=1+index, column=5, padx=10)
results_label = Label(results_frame, text=x[0])
results_label.grid(row=1+index, column=6, padx=10)
edit_button = Button(results_frame, text='E', font=('Times New Roman', 12))
edit_button.grid(row=1+index, column=7)
view_button = Button(results_frame, text='V', font=('Times New Roman', 12))
view_button.grid(row=1+index, column=8)
results_canvas.configure(yscrollcommand=scrollbar.set)
results_frame.bind('<Configure>', lambda e: results_canvas.configure(scrollregion=results_canvas.bbox("all")))
active_tab = 'Talent'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

