gpt4 book ai didi

Python Tkinter 命令单击

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:57 24 4
gpt4 key购买 nike

我需要将命令按钮单击绑定(bind)到 python 中的函数。我已经将 flag 功能绑定(bind)到右键单击,但这仅在用鼠标右键单击时有效。当我在笔记本电脑上编写大部分代码时,这非常不方便。这是我目前拥有的:

    # 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,只需将命令单击绑定(bind)到 self.flag。是否有可能做到这一点?

最佳答案

你可以只使用:

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

这可以在 <Button-2> 之外完成你可能还想绑定(bind) <Control-Button-1>为了兼容性。

我通常会链接到 http://infohost.nmt.edu/tcc/help/pubs/tkinter/event-modifiers.html不过目前好像down了,基本上有几个修饰符可以和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.

例如,您可以绑定(bind) <Control-Shift-Double-Button-1>如果您的程序需要如此复杂。

关于Python Tkinter 命令单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36875963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com