Python Forum
[Tkinter] Scrollbar doesn't work on Canvas in Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scrollbar doesn't work on Canvas in Tkinter
#1
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
Reply
#2
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
Reply
#3
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
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] graphyview setdata() doesn't work after recieving a mount of data ugly_curry_garlic 3 672 Nov-22-2023, 05:58 PM
Last Post: Axel_Erfurt
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,432 Aug-07-2023, 02:59 PM
Last Post: deanhystad
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 5,779 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  [Tkinter] Scrollbar apffal 7 3,061 Oct-11-2021, 08:26 PM
Last Post: deanhystad
  [Tkinter] Clickable Rectangles Tkinter Canvas MrTim 4 8,669 May-11-2021, 10:01 PM
Last Post: MrTim
  [Tkinter] Draw a grid of Tkinter Canvas Rectangles MrTim 5 7,775 May-09-2021, 01:48 PM
Last Post: joe_momma
Thumbs Up tkinter canvas; different page sizes on different platforms? philipbergwerf 4 4,043 Mar-27-2021, 05:04 AM
Last Post: deanhystad
  how to resize image in canvas tkinter samuelmv30 2 17,560 Feb-06-2021, 03:35 PM
Last Post: joe_momma
Question [Tkinter] How to configure scrollbar dimension? water 6 3,374 Jan-03-2021, 06:16 PM
Last Post: deanhystad
  how to rotate lines in tkinter canvas helpmewithpython 1 3,379 Oct-06-2020, 06:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020