Python Forum

Full Version: Scrollbar doesn't work on Canvas in Tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.
I'm trying to write a program that show a tkinter window with a list of names(labels) and a checkbox for every name in this list.

I want to be able to scroll through this list
but for some reason the scrollbar doesn't work on the canvas widget(gray, not clickable scrollbar),even if the there are more labels at the bottom of the window(the window cut all the remained names and doesn't let me scroll down.).

this is my code:
from tkinter import *

master = Tk()
master.title("Names")
master.geometry('300x200+750+480')

programs = ['yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy', 'yyy']
programs_path = []

frame = Frame(master)
frame.pack(side=LEFT)
canvas = Canvas(frame)
canvas.pack(side=LEFT, fill=Y)
scroll = Scrollbar(frame, orient=VERTICAL)
scroll.pack(side=RIGHT, fill=Y)

for i in range(len(programs)):
    program_label = Label(canvas, text=str(programs[i]))
    program_label.grid(row=i, column=0)
    check_box = Checkbutton(canvas)
    check_box.grid(row=i, column=1)

scroll.config(command=canvas.yview)
canvas.config(yscrollcommand=scroll.set)

master.mainloop()
I'm using Python3 with the tkinter module.
what I'm doing wrong here? Wall

thanks
Cannot help you with this question as I do not do Tkinter but please next time put Tkinter in the subject like you see in other posts so that folks that do not do Tkinter know that this is something they need not look at. Thanks
You can scroll a Canvas, Entry, Listbox, and Text widget. Try with the Scrollbar on the Canvas. Also, you do not grid() widgets to the Canvas; those should go into the Frame within the Canvas. http://effbot.org/tkinterbook/canvas.htm
just a couple observations: your:
canvas.pack(side=LEFT, fill=Y) 
may work better with expand and you're missing a canvas config:
canvas.config(width=400,height= 1000, bg='dodgerblue')
canvas.config(scrollregion=(0,0,400,1000))
canvas.pack( expand=YES, fill=BOTH)
I found it easier to use the Scrollbar in a class-
J