python - 更改滚动条(鼠标滚轮)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)
解决方案
推荐阅读
- php - 使用 curl 发生 API 错误时如何读取响应正文?
- python - Python中的嵌套总和
- asp.net - 轻松/支持将 APB(ASP.NET 样板)添加到现有 ASP.NET Core 项目
- c++ - 为什么我的节点在使用 free() 或 delete 时没有被删除
- c# - SpreadsheetLight 更新 excel 文件
- javascript - 从窗口捕获 mouseout 事件并查看退出是否来自窗口顶部
- linq - PredicateBuilder 在 Linq 中查询逗号分隔的字符串
- bash - slurm、srun 和并行
- jquery - 在没有列包装器的情况下并排浮动堆叠的 div
- docusignapi - 尝试从 REST API 检索文档时出现错误代码“INVALID_USERID”