0

I am new to Tkinter and I want to make a scrollbar.

I followed some tutorials and referenced several codes online, yet my scrollbar still do not scroll through my table.

Can someone give hints about what I did wrong?

ladderFrame = Frame(ladderWindow, bg = "white", relief="flat", height=200, width=320)
ladderFrame.place(x=477,y=280)
canvas = Canvas(ladderFrame, bg="white",height=200,width=320)
#creating scrollbar and attaching it on canvas 
scroll_bar = Scrollbar(ladderFrame, orient=VERTICAL, command=canvas.yview)
scroll_bar.grid(row=0,column=1, sticky="ns")
canvas.config(width=320,height=200)
canvas.config(yscrollcommand=scroll_bar.set)
canvas.config(scrollregion=(0,0,200,600))
canvas.grid(row=0,column=0)
LadderFile = open("ladder.txt", "r") # opening data file containing current ladder
ladder_content = LadderFile.readlines()
ranks = len(ladder_content) # getting the total number of players in the ranks 
for line in range(ranks): # for loop to put the player's corresponding ranks
    name = ladder_content[line]
    ladder_content[line] = ((line+1),name)
# creating table that will act as ladder
for i in range(ranks):
    for j in range(2):
        ladder = Entry(canvas,width = 20, fg="black", font=('Helvetica','12'))
        ladder.grid(row=i, column=j)
        ladder.insert(END, ladder_content[i][j])
        ladder.config(state=DISABLED)
LadderFile.close() #closing data file
piertoni
  • 1,933
  • 1
  • 18
  • 30
  • When you create a widget inside a canvas you don't call `ladder.grid(...)`. Instead look at [this](https://stackoverflow.com/a/11981214/11106801) – TheLizzard Apr 11 '21 at 13:04
  • The problem lies in the anchoring of your Entry widgets. You anchor them to the grid within the canvas widget instead of fixed positions on the canvas. You have to put them in windows inside the canvas. Use: `canvas.create_window(x,y,window=ladder)` to attach the Entry widget to a fixed position of your canvas. So, when the canvas moves, your widgets will move with it. – Martin Wettstein Apr 12 '21 at 09:11

0 Answers0