I was wondering if it was possible to have the same event(like-R-click/R-mouse-press), mean different things for different functions:
For example: Moving an object on R-mouse press and also having the same event used for changing the shape of an object(by mouse press and drag).
How can i do this?
You can define event pattern in tkinter and they have the form of <modifier-modifier-type-detail>
.
So what you can do is to combine event modifier such as Button3
and types as Motion
with each other, (eg) root.bind('<Button3-Motion>',button3motion)
An example can be found below:
import tkinter as tk
def button3press(event):
print('right click')
def button3release(event):
print('right click ended')
def button3motion(event):
print('mouse move while right click')
root = tk.Tk()
root.bind('<ButtonPress-3>',button3press)
root.bind('<ButtonRelease-3>',button3release)
root.bind('<B3-Motion>',button3motion)
root.mainloop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.