Python Forum
Scroll frame with MouseWheel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scroll frame with MouseWheel
#1
Hi,

I would like to make a widget to pass picture with scroll button. Below is my code however I cannot pass images while scroll button is working. Any idea how to change it? Thanks in advance.

root = tkinter.Tk()
root.wm_title("Try MouseWheel")

def imageShow():

    global fig
    fig = Figure()
    fig.add_subplot().imshow(imageDim[:, :, slide], cmap='gray', vmin=minInt, vmax=maxInt)
    canvas = FigureCanvasTkAgg(fig, master=root)
    canvas.draw()
    canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand='true')
    root.bind("<MouseWheel>", mouse_wheel)



def clearfig():
    fig.clear()


def mouse_wheel(event):
    global slide
    print(slide)
    # respond to Linux or Windows wheel event

    if event.num == 5 or event.delta == -120:
        slide -= 1

    if event.num == 4 or event.delta == 120:
        slide += 1
    clearfig()

imageShow()
root.mainloop()
Reply


Messages In This Thread
Scroll frame with MouseWheel - by Nemesis - Mar-25-2020, 09:04 AM
RE: Scroll frame with MouseWheel - by Nemesis - Mar-25-2020, 09:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] QTableView: scroll to top cell of the screen random_nick 2 2,853 Oct-08-2022, 12:29 AM
Last Post: random_nick
  [PyQt] How do I get a QScrollArea to scroll? LavaCreeperKing 9 7,843 Oct-29-2021, 08:33 AM
Last Post: Axel_Erfurt
  Treeview scroll selected node to top rfresh737 1 2,717 Apr-14-2021, 03:27 AM
Last Post: deanhystad
  [Tkinter] canvas widget scroll issue chrisdb 2 3,867 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  [Tkinter] Help with scroll bars kraco 1 2,249 Sep-27-2020, 11:20 PM
Last Post: Larz60+
  [Tkinter] How to place scroll bar correctly scratchmyhead 1 3,954 May-18-2020, 04:17 PM
Last Post: scratchmyhead
  [Kivy] Why I have to click twice to scroll? Hummingbird 0 2,371 Jan-06-2020, 09:08 PM
Last Post: Hummingbird
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 9,023 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] Scroll Bars going backwards goofygoo 2 2,706 Jun-07-2019, 05:07 PM
Last Post: goofygoo
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,137 Apr-18-2019, 05:36 PM
Last Post: atlass218

Forum Jump:

User Panel Messages

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