I have a tkinker window with several buttons and layouts that use place. I tried to create a scrollbar to the entire window. I added a scroolbar for a window with grid . The scroolbar doesn't scrool. I don't understand what is wrong. This is my code:
import tkinter as tk
...
def get_text():
...
m=len(obj_list) if len(obj_list)>m else m
for i in range(m):
try:
guidelines = tk.Label(window, text="{0} : {1} ore ({2} ore si {3} minute )".format(obj_list[i].name,'%.2f'%obj_list[i].nr_ore, int(obj_list[i].nr_ore),int((obj_list[i].nr_ore-int(obj_list[i].nr_ore))*60)+1), fg="blue", cursor="hand2")
guidelines.grid(row=7+i, column=0, sticky='nsew')
guidelines.bind("<Button-1>", lambda event, a=obj_list[i].data,b=obj_list[i].nr_in,c=obj_list[i].nr_out: show_guide_lines(a,b,c))
except:
guidelines = tk.Label(window, text='')
guidelines.grid(row=7+i, column=0, sticky='nsew')
frame=tk.Frame(window, width=500, height=10+len(obj_list))
def show_guide_lines(data_list,nrIn_list,nrOut_list):
window_guide_lines = tk.Toplevel(window)
window_guide_lines.title('')
window_guide_lines.geometry('400x200')
txt = ''
for a,b,c in zip(data_list,nrIn_list,nrOut_list) :
txt=txt+'\n'+'{0}/{1}/{2} : {3} intrari, {4} iesiri'.format(a.day,a.month,a.year,b,c)
tk.Label(window_guide_lines, text=txt).pack()
window_guide_lines.tkraise()
window_guide_lines.focus_force()
mFrame = tk.Tk()
mFrame.geometry("1300x775")
mFrame.configure(background="Gray")
mFrame.columnconfigure(0, weight=1)
mFrame.rowconfigure(0, weight=1)
frame_canvas = tk.Frame(mFrame)
frame_canvas.grid(row=0, column=0, sticky='news')
Can1 = tk.Canvas(frame_canvas, width=500, height=500)
Can1.grid(row=0, column=0)
vsbar = tk.Scrollbar(frame_canvas, orient="vertical", command=Can1.yview)
vsbar.grid(row=0, column=1, sticky='ns')
Can1.configure(yscrollcommand=vsbar.set)
window = tk.Frame(Can1)
Can1.create_window((0,0), window=window,anchor='nw')
#window=tk.Tk()
#window.title('Calculare numar de ore')
#window.eval('tk::PlaceWindow . center')
##Scrollbar-ul
frame=tk.Frame(window, width=500, height=30)
frame.grid(row=0,column=0)
#Butonul de inserare a fisierelor excel
button=tk.Button(text='Insert Excel File', command=getExcel)
button.grid(row=1, column=0, sticky='nsew')
label1=tk.Label(window, text="", font=('Calibri 9'))
label1.grid(row=2, column=0, sticky='nsew')
label2=tk.Label(window, text="Introduceti persoana:", font=('Calibri 11'))
label2.grid(row=3, column=0, sticky='nsew')
text=tk.Text(window, height=1)
text.grid(row=4, column=0)
#Butonul de executie de dupa introducerea textului
get_button=tk.Button(window, text='Calculeaza', command=get_text)
get_button.grid(row=5, column=0, sticky='nsew')
label3=tk.Label(window, text="", font=('Calibri 15'))
label3.grid(row=6, column=0, sticky='nsew')
window.mainloop()
mFrame.mainloop()
and it doesn't work. It should work but the scrrolbar doesn't scroll. Thank you in advance!!!
You need to update the scrollregion option of Can1
whenever items are added to window
frame by binding the event <Configure>
to window
frame:
window.bind("<Configure>", lambda e:Can1.config(scrollregion=Can1.bbox("all")))