Python Forum
[Tkinter] Scrollbars on canvas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scrollbars on canvas
#1
Hello,
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 = Image.open(filename)
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
Reply
#2
Use the ScrolledFrame from Pmw http://pmw.sourceforge.net/doc/ScrolledFrame.html or PyPi https://pypi.org/project/tkScrolledFrame/
Reply
#3
woooee thank you for your advice. tkScrolledFrame works in my app.
Reply


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

Forum Jump:

User Panel Messages

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