Juan Dougnac
Juan Dougnac

Reputation: 95

Tkinter scroll bar not scrolling

I am trying to create a gui with two canvas and a scrolling bar going through both at the same time, as a test for another project. I have created the root, the two canvas and pinned some labels to each using the grid method, as well as created the scroll bar.

However, when I run the program, the scroll bar moves fines, but the content of the window doesn't change at all, as if the bar wasn't working. I have tried a few solutions by googling my problem, but so far I haven't been able to solve it.

The relevant code is

from tkinter import *
root = Tk()
‪#‎scroll‬
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
firstCanvas = Canvas(root, width=200, height=100)
firstCanvas.pack(side="left", fill="both", expand=True)
secondCanvas = Canvas(root, width=20000, height=10000,scrollregion=(0,0,0,5000),yscrollcommand=scrollbar.set)
secondCanvas.pack(side="left", fill="both", expand=True)
secondCanvas.create_rectangle((200,300,300,6000))
widget = Label(firstCanvas, text='Spam')
widget.pack()

# Lots of widgets so they reach beyond the screen, all in the following format

widgetOne=Label(firstCanvas, text="this is a test")
widgetOne.pack()
widgetTwo=Entry(firstCanvas)
widgetTwo.pack()
widgetThree=Label(secondCanvas, text='Spam')
widgetFour=Entry(secondCanvas)
widgetFour.pack()   

scrollbar.config(command=secondCanvas.yview)
mainloop()

Upvotes: 2

Views: 1739

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385860

The canvas will only scroll canvas objects. For widgets, that means widgets created with canvas.create_window(...)

See Adding a scrollbar to a group of widgets in Tkinter

Upvotes: 3

Related Questions