0

I have the following code:

tabControl = Notebook(root)

tab0 = Frame(tabControl)
tab0.pack(fill="both")
tabControl.add(tab0, text="Wardrobe")
tab1 = Frame(tabControl)
tab1.pack(fill='both')
tabControl.add(tab1, text='Weapons', state='normal')
tab2 = Frame(tabControl)
tab2.pack(fill='both')
tabControl.add(tab2, text='Ammo', state='normal')

tabControl.pack(expand=1, fill="both")

# determine canvas
w = 1000
h = 1500

canvas = Canvas(tab0, width=w, height=h, relief='ridge', scrollregion=(0, 0, w, h), highlightthickness=0)

sbar = Scrollbar(tab0, orient=VERTICAL)
sbar.pack(side=RIGHT, fill=Y)
sbar.config(command=canvas.yview)
canvas.config(width=w, height=h)
canvas.config(yscrollcommand=sbar.set)
canvas.pack(side=LEFT, expand=True, fill=BOTH)

# WARDROBE
# photos
planep = PhotoImage(file='images/plane pic.png')
plane = Label(canvas, image=planep)
plane.pack()
plane.place(relx=0.3, y=100, anchor='center')

I managed to get the scrollbar moving but when I "scroll" nothing really happens on the screen except the scrollbar moving (image labels are staying in the same place all the time). I also added an example of adding an image label to it since I think the problem lies in determining y=100 in placing the plane picture. Does anyone have an idea what should I do? Thanks in advance.

Space0Code
  • 13
  • 2
  • Does this help you ? https://stackoverflow.com/questions/63216149/tkinter-canvas-scrollbar-greyed-out – Delrius Euphoria Aug 02 '20 at 16:54
  • You can simply replace the last three lines by `canvas.create_image(0, 0, image=planep, anchor='nw')` and set the height of canvas less than `h`. – acw1668 Aug 02 '20 at 17:28
  • I first tried out the solution provided by @acw1668, since it was the most straight-forward one. It worked immediately, so thank you. Correct me if I'm wrong, but I think the problem was me not drawing images onto canvas but on the tab0 instead. This has resulted in an illusion that the canvas isn't moving although it was, right? – Space0Code Aug 02 '20 at 17:49
  • Yes, sort of. You should use `canvas.create_xxxxxx()` functions to put objects into canvas. – acw1668 Aug 02 '20 at 18:05

0 Answers0