![](/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.