1

I have a tkinter canvas where I put labels on. When too many labels are added to the canvas, it grows out of the bottom of the screen. How do I set a max size on the canvas and make it decently scrollable?

middleCanvas = Canvas(window, bg="red", width=300, height=400)



middleCanvas.grid(column=1, row=3, sticky="N")
scroll_y.grid(column=2, row=3, sticky="NS")
middleCanvas.configure(yscrollcommand=scroll_y.set)
middleCanvas.configure(scrollregion=middleCanvas.bbox("all"))


messageLabel = Label(middleCanvas, text=line)
messageLabel.grid(column=1, row=messageRow)

Tried using a scrollbar, but the bar also goes out of screen and fills the slider.

1 Answers1

1

This also happened to me with buttons. You can fix it by defining a WIDTH and HEIGHT variable and set them to the size you want. Then set the Label width to the WIDTH and the height to the HEIGHT variable. For example:

WIDTH = 5
HEIGHT = 2
messagelabel = Label(middleCanvas, text="A very, very, very  very, very long string. ", width=WIDTH, height=HEIGHT)
messagelabel.grid(column=1, row=messageRow) 
  • Also if this answer has helped you, please mark it as a solution by clicking the checkmark. –  Dec 04 '22 at 16:25
  • Sorry for maybe being unclear, but my canvas expands to the bottom of the screen, not the side. And I already gave the canvas a height. – Kobe Motmans Dec 06 '22 at 13:33
  • You can just set the `HEIGHT` variable. Also set them for the labels –  Dec 06 '22 at 14:05