python - 如何在 tkinter 中使用鼠标滚轮进行滚动
问题描述
我希望能够用鼠标滚轮在 tkinter 中向下滚动我的列表。我怎样才能做到这一点?
我已经尝试定义鼠标滚轮功能并将鼠标滚轮绑定到画布框架。但它没有用。
from tkinter import *
def update_scrollregion(event):
photoCanvas.configure(scrollregion=photoCanvas.bbox("all"))
root = Tk()
root.geometry("1700x900")
photoFrame = Frame(root, width=250, height=190, bg="#EBEBEB")
photoFrame.grid()
photoFrame.rowconfigure(0, weight=1)
photoFrame.columnconfigure(0, weight=1)
photoCanvas = Canvas(photoFrame, bg="#EBEBEB")
photoCanvas.grid(row=0, column=0, sticky="nsew")
canvasFrame = Frame(photoCanvas, bg="#EBEBEB")
photoCanvas.create_window(0, 0, window=canvasFrame, anchor='nw')
i = 1
while i < 77:
Label(canvasFrame,text="example",padx=15).grid(row=i,column=1,sticky="W")
i += 1
photoScroll = Scrollbar(photoFrame, orient=VERTICAL)
photoScroll.config(command=photoCanvas.yview)
photoCanvas.config(yscrollcommand=photoScroll.set)
photoScroll.grid(row=0, column=1, sticky="ns")
canvasFrame.bind("<Configure>", update_scrollregion)
root.mainloop()
解决方案
推荐阅读
- spring - 在单个应用程序上下文中使用 Netty 的 Tomcat
- pip - Raspberry Pi 4B 上的 Ansible 需要很长时间才能返回任何命令
- flutter - 颤振悠悠球播放器控制器
- apache-kafka - 带有函数式编程的 spring-cloud-stream
- sql - 错误的原因是什么,cx_Oracle.DatabaseError: ORA-24909: call in progress
- graphql - KeystoneJS 关系,如何使用 id 数组进行连接
- javascript - 多个 webdatarocks 在同一页面上旋转异常 DisplayGrids
- sharepoint - 如何从 Sharepoint / Onedrive 文件选择器中获取长寿命的可嵌入链接?
- python - 在 python win32 中为 excel 激活特定单元格
- javascript - 如何在 Spring-Boot 应用程序中使用 JavaScript 加入枚举