Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Scrollbars on canvas
I'm trying to create a image viewer in tkinter. I have problem with scrollbars in my app. I want horizontal and vertical scrollbars next to image when the image is zoomed. I use following code to do this (part of my code):
image =
photo = ImageTk.PhotoImage(image)
if zoom > 1:
        canvas = Canvas(root, width = w*zoom, height = h*zoom, bg=bgcolor)
        canvas.pack(side="top", expand=1, fill=BOTH)
        scroll_bar_x = Scrollbar(canvas, orient = tkinter.HORIZONTAL)
        scroll_bar_x.pack(side="bottom", fill = X, expand= 0)
        scroll_bar_y = Scrollbar(canvas, orient = tkinter.VERTICAL)
        scroll_bar_y.pack(side="right", fill = Y, expand= 0)
        scroll_bar_x["command"] = canvas.xview
        scroll_bar_y["command"] = canvas.yview
        canvas["xscrollcommand"] = scroll_bar_x.set
        canvas["yscrollcommand"] = scroll_bar_y.set
        canvas.create_image(w*zoom/2, h*zoom/2, image=photo)
I see scrollbars next to image but they don't work. I can't use them.
In what part of the code do I have a mistake?

Thank you, Christina
Use the ScrolledFrame from Pmw or PyPi
woooee thank you for your advice. tkScrolledFrame works in my app.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 7,843 Jun-04-2019, 05:05 AM
Last Post: Gupi

Forum Jump:

Users browsing this thread: 1 Guest(s)