0

I get a scrollbar on myscreen , but when I use it my page stays still, but my scroll bar moves!. How do I correct my code to move my page using scrollbar?

from tkinter import *
from PIL import ImageTk,Image
root=Tk()

canvas = Canvas(root, bd=0,height=1000,width=1000,scrollregion=(0,0,1500,1500))
frame = Frame(canvas, bd=2,height=1500,width=1500,bg='salmon',relief=SUNKEN)
frame.pack(expand=True, fill=BOTH)
hbar=Scrollbar(root,orient=HORIZONTAL)
hbar.pack(side=BOTTOM,fill=X)
hbar.config(command=canvas.xview)
vbar=Scrollbar(root,orient=VERTICAL)
vbar.pack(side=RIGHT,fill=Y)
vbar.config(command=canvas.yview)


canvas.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)
canvas.pack(side=LEFT,expand=True,fill=BOTH)
canvas.config(scrollregion=canvas.bbox(ALL))
L = Label(frame, text=" NAME OF THE STUDENT ",font=('segoe script', 20,'bold'),bg='yellow2',fg='maroon',relief='raised',bd=9)
L.place(relx=0.05,rely=0.5)


L1 = Label(frame, text=" USER NAME ",font=('segoe script', 20,'bold'),bg='yellow2',fg='maroon',relief='raised',bd=9)
L1.place(relx=0.05,rely=0.6)
E1 = Entry(frame, bd =10,width=20,selectborderwidth=2,relief='groove',font=('segoe script', 20,'bold'),fg='maroon')
E1.place(relx=0.35,rely=0.6)



L2 = Label(frame, text=" PASSWORD ",font=('segoe script', 20,'bold'),bg='yellow2',fg='maroon',relief='raised',bd=9)
L2.place(relx=0.05,rely=0.7)
E2 = Entry(frame, bd =10,width=15,selectborderwidth=2,relief='groove',font=('segoe script', 20,'bold'),fg='maroon',show='*')
E2.place(relx=0.35,rely=0.7)



L3 = Label(frame, text=" CONFIRM PASSWORD ",font=('segoe script', 20,'bold'),bg='yellow2',fg='maroon',relief='raised',bd=9)
L3.place(relx=0.05,rely=0.8)
E3 = Entry(frame, bd =10,width=15,selectborderwidth=2,relief='groove',font=('segoe script', 20,'bold'),fg='maroon',show='*')
E3.place(relx=0.55,rely=0.8)



stud_bt=Button(frame,text=' CREATE ACCOUNT ',font=('segoe script', 11,'bold'),height=2,width=15,bg='dark orchid4',fg='floralwhite',bd=8)
stud_bt.place(relx=0.39,rely=0.9)

frame.pack()
root.mainloop()"""
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
KSM
  • 1
  • Does this answer your question? [Adding a scrollbar to a group of widgets in Tkinter](https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter) – Thingamabobs Aug 07 '20 at 16:11
  • 1
    Welcome to SO, please provide minimal-reproducible-example, there seems to be a lot of code for your question. Also please do some research before asking, there are quiet a lot of simliar questions to yours at SO. Last but nut least, check your code for "onFrameConfigure" in the link. – Thingamabobs Aug 07 '20 at 16:19
  • Thank you. I'm not able to get it right. How do I modify the program? Kindly help me with that. – KSM Sep 02 '20 at 07:43
  • @Atlas435 . Pls help me out . – KSM Sep 08 '20 at 11:13

1 Answers1

1

You must set the scrollregion after adding all of the content to the canvas. Otherwise the scrollregion will be None.

Also, you can't use pack to put the frame in the canvas. You must use the create_window method of the canvas. You can only scrollitems created by the canvas, not items added with pack, grid, or place.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685