簡體   English   中英

Python Tkinter命令單擊

[英]Python Tkinter Command Click

我需要將命令按鈕單擊綁定到python中的函數。 我已經將標記函數綁定到右鍵單擊,但這只有在用鼠標右鍵單擊時才有效。 當我在筆記本電腦上編寫大部分代碼時,這非常不方便。 這是我目前擁有的:

    # set up the mouse click listeners
    self.bind('<Button-1>',self.expose)
    self.bind('<Button-2>',self.flag)
    #this is where I want to bind self.flag to command click   

我想盡可能使用self.bind,只需將命令單擊綁定到self.flag即可。 是否有可能做到這一點?

你可以使用:

self.bind("<Command-Button-1>",self.flag)

這可以在<Button-2> ,您可能還想綁定<Control-Button-1>以實現兼容性。

我通常會鏈接到http://infohost.nmt.edu/tcc/help/pubs/tkinter/event-modifiers.html但目前似乎有所下降,基本上有一些修飾符可以組合使用使用ButtonKey

Alt      True when the user is holding the alt key down.
Any      This modifier generalizes an event type. For example, the event pattern '<Any-KeyPress>' applies to the pressing of any key.
Control  True when the user is holding the control key down.
Double   Specifies two events happening close together in time. For example, <Double-Button-1> describes two presses of button 1 in rapid succession.
Lock     True when the user has pressed shift lock.
Shift    True when the user is holding down the shift key.
Triple   Like Double, but specifies three events in rapid succession.

因此,如果你的程序需要精心設計,你可以綁定<Control-Shift-Double-Button-1>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM