-1

I developed a small tkinter GUI to display (and export) images stored in a proprietary format. I managed to load the data into a 3D numpy uint8 array. I want to display one slice of that 3D array in a tkinter.canvas. To do so I used ImageTk.PhotoImage.

Underneath the Canvas I inserted a tk.Scrollbar. My goal is to use that scrollbar to let the user actively "scroll" though the 3D Array. Basically when the slider is moved or any of the arrows is pressed the slice corresponding to the slider position should be displayed in the canvas.

Right now I have the issue that I don't understand how to set the range of the scrollbar to my z-Dimension and then how to bind the scrollbar events to the movement or arrow actions to update the canvas.

Right now I don't have example code since this is a more conceptual problem.

Could you point me in the right direction how to solve this?

Best TMC

edit: Photo

Tkinter Gui with Canvas and Scrollbar

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
TMC
  • 75
  • 10
  • Descriptions of code are largely useless, and links to code on other sites is discouraged. Please try to create a [mcve]. – Bryan Oakley Sep 24 '20 at 23:48

1 Answers1

0

The solution is to use tkinter.Scale instead of tkinter.Scrollbar . As a side note, the command within:

scale = tk.Scale(yourTkFrame, from_=min, to=max, orient='horizontal', command=doSomething)

passes two values to the function doSomething.

Using the Scale allows to use the scale.get() method to retrieve the position between min and max values. Those can then be used to set the image corresponding to the selected position on the slide.

TMC
  • 75
  • 10