首页 > 解决方案 > 更改滚动条(鼠标滚轮)tkinter Python的滚动速度

问题描述

我想用鼠标滚轮改变我的滚动条速度,因为它太快而且看起来不像你在滚动。我想将轮速设置为单击滚动条时的速度。这是我的滚动条代码:

class VerticalScrolledFrame(tkinter.Frame):
    """A pure Tkinter scrollable frame that actually works!

    * Use the 'interior' attribute to place widgets inside the scrollable frame
    * Construct and pack/place/grid normally
    * This frame only allows vertical scrolling
    """
    def __init__(self, parent, *args, **kw): #Arguemnts
        tkinter.Frame.__init__(self, parent, *args, **kw) #Arguments            

        parent.update() #Update the parent for get the correct size

        # create a self.canvas object and a vertical scrollbar for scrolling it
        self.vscrollbar = tkinter.Scrollbar(self, orient=tkinter.VERTICAL)
        self.vscrollbar.pack(fill=tkinter.Y, side=tkinter.RIGHT, expand=tkinter.FALSE)
        self.canvas = tkinter.Canvas(self, bd=0, highlightthickness=0, yscrollcommand=self.vscrollbar.set, height=parent.winfo_height(), width=parent.winfo_width())
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))
        
        self.canvas.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=tkinter.TRUE)
        self.vscrollbar.config(command=self.canvas.yview)

        # reset the view
        self.canvas.xview_moveto(0)
        self.canvas.yview_moveto(0)

        # create a frame inside the self.canvas which will be scrolled with it
        self.interior = interior = tkinter.Frame(self.canvas)
        interior_id = self.canvas.create_window(0, 0, window=interior,
                                           anchor=tkinter.NW)
        
        # track changes to the self.canvas and frame width and sync them,
        # also updating the scrollbar
        def _configure_interior(event):
            # update the scrollbars to match the size of the inner frame
            size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
            self.canvas.config(scrollregion="0 0 %s %s" % size)
            
            if interior.winfo_reqwidth() != self.canvas.winfo_width():
                # update the self.canvas's width to fit the inner frame
                self.canvas.config(width=interior.winfo_reqwidth())
                
        interior.bind('<Configure>', _configure_interior)

        def _configure_canvas(event):
            if interior.winfo_reqwidth() != self.canvas.winfo_width():
                # update the inner frame's width to fill the self.canvas
                self.canvas.itemconfigure(interior_id, width=self.canvas.winfo_width())
        self.canvas.bind('<Configure>', _configure_canvas)

标签: pythonpython-3.xtkinter

解决方案


推荐阅读