how to create a full screen scrollbar in tkinter

Solutions on MaxInterview for how to create a full screen scrollbar in tkinter by the best coders in the world

showing results for - "how to create a full screen scrollbar in tkinter"
Jeanna
15 Feb 2020
1from tkinter import *
2from tkinter import ttk
3
4root=Tk()
5root.title("Create Full Screen scrollbar")
6
7# width=400, height=400
8root.geometry("400x400")
9
10#create a Main Frame
11main_frame=Frame(root)
12main_frame.pack(fill=BOTH,expand=1)
13
14#Create A Canvas
15my_canvas=Canvas(main_frame)
16my_canvas.pack(side=LEFT,fill=BOTH,expand=1)
17
18#Add A Scrollbar To The Canvas
19my_scrollbar=ttk.Scrollbar(main_frame,orient=VERTICAL,command=my_canvas.yview)
20my_scrollbar.pack(side=RIGHT,fill=Y)
21
22#Configure Canvas
23my_canvas.configure(yscrollcommand=my_scrollbar.set)
24my_canvas.bind("<Configure>",lambda e: my_canvas.configure(scrollregion=my_canvas.bbox("all")))
25
26#Create Another Frame INSIDE The Canvas
27second_frame=Frame(my_canvas)
28
29#Add That New frame To a Window In Canvas
30my_canvas.create_window((0,0),window=second_frame,anchor="nw")
31
32
33# Now put you widgets in second_frame
34
35for thing in range(100):
36    Button(second_frame,text=f'Button {thing} Yo!').grid(row=thing,column=0,pady=10,padx=10)
37
38
39
40
41root.mainloop()