- # explore the mouse wheel with the Tkinter GUI toolkit
- # Windows and Linux generate different events
- # tested with Python3.0
- import tkinter as tk
- def mouse_wheel(event):
- global count
- # respond to Linux or Windows wheel event
- if event.num == 5 or event.delta == -120:
- count -= 1
- if event.num == 4 or event.delta == 120:
- count += 1
- label['text'] = count
- count = 0
- root = tk.Tk()
- root.title('turn mouse wheel')
- root['bg'] = 'darkgreen'
- # with Windows OS
- root.bind("
" , mouse_wheel) - # with Linux OS
- root.bind("
" , mouse_wheel) - root.bind("
" , mouse_wheel) - label = tk.Label(root, font=('courier', 18, 'bold'), width=10)
- label.pack(padx=40, pady=40)
- root.mainloop()
Using the Mouse Wheel with Tkinter (Python)
标签:
python
订阅:
博文评论 (Atom)
没有评论:
发表评论