Answers for "how to create a full screen scrollbar in tkinter"

0

how to create a full screen scrollbar in tkinter

from tkinter import *
from tkinter import ttk

root=Tk()
root.title("Create Full Screen scrollbar")

# width=400, height=400
root.geometry("400x400")

#create a Main Frame
main_frame=Frame(root)
main_frame.pack(fill=BOTH,expand=1)

#Create A Canvas
my_canvas=Canvas(main_frame)
my_canvas.pack(side=LEFT,fill=BOTH,expand=1)

#Add A Scrollbar To The Canvas
my_scrollbar=ttk.Scrollbar(main_frame,orient=VERTICAL,command=my_canvas.yview)
my_scrollbar.pack(side=RIGHT,fill=Y)

#Configure Canvas
my_canvas.configure(yscrollcommand=my_scrollbar.set)
my_canvas.bind("<Configure>",lambda e: my_canvas.configure(scrollregion=my_canvas.bbox("all")))

#Create Another Frame INSIDE The Canvas
second_frame=Frame(my_canvas)

#Add That New frame To a Window In Canvas
my_canvas.create_window((0,0),window=second_frame,anchor="nw")


# Now put you widgets in second_frame

for thing in range(100):
    Button(second_frame,text=f'Button {thing} Yo!').grid(row=thing,column=0,pady=10,padx=10)




root.mainloop()
Posted by: Guest on September-06-2021

Code answers related to "how to create a full screen scrollbar in tkinter"

Python Answers by Framework

Browse Popular Code Answers by Language