I have realised that the scrollbar in Tkinter is by default hidden unless and until you have put enough texts,buttons,etc on your frame to make the screen scrollable. Is there any way to show the scrollbar even when there's nothing present inside the frame?
The photo shown in the first link has the text "Sample scrolling label" only once whereas in the next link the text "Sample scrolling label" is shown 150 times and the scrollbar is now visible
Here is my code
from tkinter import *
root = Tk()
root.geometry("1366x768")
container = Frame(root)
canvas = Canvas(container)
scrollbar = Scrollbar(container,cursor="dot",width=30, orient="vertical",
command=canvas.yview,elementborderwidth=100)
scrollable_frame = Frame(canvas)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all",10,10)
)
)
canvas.create_window((0,0),width=200, window=scrollable_frame)
canvas.configure(yscrollcommand=scrollbar.set)
for i in range(150):
Label(scrollable_frame, text="Sample scrolling label").pack()//This text appears on the frame 150
times
container.place(x=500,y=0,height=700,width=868)
canvas.pack(side=LEFT, fill=BOTH, expand=False)
scrollbar.pack(side="right", fill="y")
root.mainloop()