所有Tkinter事件列表

mcu*_*mcu 22 python events tkinter tcl

在Python tkinter模块,<Button-1>,<Button-2><Button-3>分别用于确定左,中,右按钮鼠标按钮点击.

同样,<KeyPress-Return>用于返回键按下.

我在哪里可以找到所有此类事件的列表,包括各种键盘键的名称?

Tcl绑定手册没有那些.

alb*_*ert 30

绑定和事件的一般列表可以在effbot.orgNew Mexico Tech提供文档中找到,而除了原始文档之外,这里还列出了几个键的名称.

以下是一些最常见事件的摘要,其中包含一些按键名称:

<Button-1>        Button 1 is the leftmost button, button 2 is the middle button
                  (where available), and button 3 the rightmost button.

                  <Button-1>, <ButtonPress-1>, and <1> are all synonyms.

                  For mouse wheel support under Linux, use Button-4 (scroll 
                  up) and Button-5 (scroll down)

<B1-Motion>       The mouse is moved, with mouse button 1 being held down (use
                  B2 for the middle button, B3 for the right button).

<ButtonRelease-1> Button 1 was released. This is probably a better choice in 
                  most cases than the Button event, because if the user 
                  accidentally presses the button, they can move the mouse 
                  off the widget to avoid setting off the event.

<Double-Button-1> Button 1 was double clicked. You can use Double or Triple as 
                  prefixes.

<Enter>           The mouse pointer entered the widget (this event doesn’t mean 
                  that the user pressed the Enter key!).

<Leave>           The mouse pointer left the widget.

<FocusIn>         Keyboard focus was moved to this widget, or to a child of 
                  this widget.

<FocusOut>        Keyboard focus was moved from this widget to another widget.

<Return>          The user pressed the Enter key. For an ordinary 102-key 
                  PC-style keyboard, the special keys are Cancel (the Break 
                  key), BackSpace, Tab, Return(the Enter key), Shift_L (any 
                  Shift key), Control_L (any Control key), Alt_L (any Alt key), 
                  Pause, Caps_Lock, Escape, Prior (Page Up), Next (Page Down), 
                  End, Home, Left, Up, Right, Down, Print, Insert, Delete, F1, 
                  F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, Num_Lock, and 
                  Scroll_Lock.

<Key>             The user pressed any key. The key is provided in the char 
                  member of the event object passed to the callback (this is an 
                  empty string for special keys).

a                 The user typed an “a”. Most printable characters can be used 
                  as is. The exceptions are space (<space>) and less than 
                  (<less>). Note that 1 is a keyboard binding, while <1> is a 
                  button binding.

<Shift-Up>        The user pressed the Up arrow, while holding the Shift key 
                  pressed. You can use prefixes like Alt, Shift, and Control.

<Configure>       The widget changed size (or location, on some platforms). The 
                  new size is provided in the width and height attributes of 
                  the event object passed to the callback.

<Activate>        A widget is changing from being inactive to being active. 
                  This refers to changes in the state option of a widget such 
                  as a button changing from inactive (grayed out) to active.


<Deactivate>      A widget is changing from being active to being inactive. 
                  This refers to changes in the state option of a widget such 
                  as a radiobutton changing from active to inactive (grayed out).

<Destroy>         A widget is being destroyed.

<Expose>          This event occurs whenever at least some part of your 
                  application or widget becomes visible after having been
                  covered up by another window.

<KeyRelease>      The user let up on a key.

<Map>             A widget is being mapped, that is, made visible in the 
                  application. This will happen, for example, when you call the 
                  widget's .grid() method.

<Motion>          The user moved the mouse pointer entirely within a widget.

<MouseWheel>      The user moved the mouse wheel up or down. At present, this 
                  binding works on Windows and MacOS, but not under Linux.

<Unmap>           A widget is being unmapped and is no longer visible.

<Visibility>      Happens when at least some part of the application window 
                  becomes visible on the screen.
Run Code Online (Sandbox Code Playgroud)

  • 不知怎的,我错过了[原始文档](http://www.tcl.tk/man/tcl8.4/TkCmd/keysyms.htm),谷歌没有多大帮助.谢谢. (3认同)
  • 我应该用谷歌搜索 [tcl keysyms](https://www.google.com/search?q=keysym&amp;ie=utf-8&amp;oe=utf-8#q=tcl+keysyms)。 (2认同)
  • 此处并未列出所有按键符号。低级的东西总是能想出我们从未听说过的键盘符号。有时,您最终不得不尝试看看。 (2认同)
  • @albert 见编辑。在清理表格并删除合并时多次提及的内容后不久。 (2认同)
  • 最新的tcl8.7文档:https://tcl.tk/man/tcl8.7/TkCmd/keysyms.html (2认同)

小智 7

class EventType尝试查看模块源代码中的定义tkinter/__init__.py

通常对我来说,如果发生异常,此模块会在我的 Wing IDE 中显示为选项卡。

  • 您能详细说明一下您的答案吗?例如,您应该提供一个示例来说明这些工具如何帮助解决问题,或者至少提供指向进一步文档的链接。 (8认同)