2016-04-26 6 views
1

私は、コマンドボタンをクリックする必要がありますPythonの関数をクリックします。私はすでに、フラグを右クリックにバインドしていますが、これはマウスで右クリックすると機能します。ラップトップに大部分のコードを書いているので、これはひどく不便です。ここで私は、現在持っているものです。Python Tkinterコマンドをクリックしてください

# 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にコマンドクリックをバインドしたいと思います。これは可能ですか?

答えて

0

あなただけ使用することができます。

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

これは<Button-2>に加えて行うことができます。また、互換性のために<Control-Button-1>をバインドすることもできます。

私は通常http://infohost.nmt.edu/tcc/help/pubs/tkinter/event-modifiers.htmlにリンクだろうが、現時点でダウンしているようだ、基本的にButtonまたはKeyと組み合わせて使用​​することができ、いくつかの修飾子があります

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. 

ですから、可能性例のバインドにあなたのプログラムが精巧である必要がある場合。

+0

ありがとうございました!私はスーパーコンパチビリティのためのシフトクリック、コントロールとコマンドも追加しました。私は編集的だから。 –

+0

ニースでは、unix(macとlinuxなど)で ''が右クリックされ、 ''はマウスの中ボタン**ですが、Windowsコンピュータではスイッチされていることにも言及する価値があります。あなたが本当にうつ病である(または['sys.platform'](https://docs.python.org/3/library/sys.html#sys.platform)をチェックして)もバインドする –

+0

また@JosiahSchmidt Iあなたは[私の答えを受け入れる]と仮定します(http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)? –

関連する問題