![](/img/trans.png)
[英]How to make Entries with the same size but different fonts in Tkinter?
[英]How to make same event mean different things for different functions in tkinter?
我想知道是否有可能有相同的事件(如-R-click/R-mouse-press),对于不同的功能意味着不同的东西:
例如:在 R 鼠标按下时移动 object 并具有用于更改对象形状的相同事件(通过鼠标按下和拖动)。
我怎样才能做到这一点?
您可以在 tkinter 中定义事件模式,它们的形式为<modifier-modifier-type-detail>
。
因此,您可以做的是将Button3
等事件修饰符和Motion
类型相互结合,(例如) root.bind('<Button3-Motion>',button3motion)
可以在下面找到一个示例:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.