Charlie
Charlie

Reputation: 11

Cannot get the scroll bar to work for a canvas in Tkinter

I have created a UI with buttons, images, ext and have managed to get a scroll bar to appear however it wont scroll up and down the canvas. I have tried multiple approaches to this, which I have found on the internet however none have worked. I recieve no error messages. Below is my code, I have kept only a small amount of labels and buttons and the main code for the scroll bar is a the top. Any help would be appreiciated, thanks.

            self.root3=tk.Toplevel()
            frame_3=tk.Frame(self.root3,width=2000,height=1080)
            frame_3.pack(expand=True, fill=BOTH) 
            canvas=Canvas(frame_3,bg='black',width=2000,height=1080,scrollregion=(0,0,4000,2060))
            hbar=Scrollbar(frame_3,orient=HORIZONTAL)
            hbar.pack(side=BOTTOM,fill=X)
            hbar.config(command=canvas.xview)
            vbar=Scrollbar(frame_3,orient=VERTICAL)
            vbar.pack(side=RIGHT,fill=Y)
            vbar.config(command=canvas.yview)
            canvas.config(width=2000,height=1080)
            canvas.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)
            canvas.pack(side=LEFT,expand=True,fill=BOTH)

            HButton = tk.Button(canvas,bg="orange",text="History",command = self.History_View)
            HButton.place(x=1000,y=20)

            Title_label = tk.Label(canvas,bg="black", fg = "orange",text ="MOVIES R US")
            Title_label.place(x=500,y=0)
            Title_label.config(font=("Ariel","20"))

            action_label=tk.Label(canvas,bg="black",fg="orange",text="ACTION")
            action_label.place(x=50,y=60)
            action_label.config(font=("Ariel","20"))

            AEGimg=tk.PhotoImage(file="AEG.gif")
            AEGlabel = tk.Label(self.root3, image=AEGimg,bd=0)#bd = 0 removes border
            AEGlabel.image= AEGimg
            AEGlabel=tk.Button(self.root3,image=AEGimg, bd=0,bg="black", command=self.AEG_film)
            AEGlabel.place(x=50,y=100, anchor= NW)

Upvotes: 1

Views: 35

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386220

You cannot use pack, grid, or place to put widgets on a canvas if you want to be able to scroll them. The canvas can only scroll items added with one of the "create" methods, such as create_window.

Upvotes: 0

Related Questions