- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 418字
- 2021-08-27 19:44:06
How it works...
The bind method is defined in the widget class and takes three arguments, an event sequence, a callback function, and an optional add string:
widget.bind(sequence, callback, add='')
The sequence string uses the <modifier-type-detail> syntax.
In first place, modifiers are optional and allow you to specify additional combinations to the general type of the event:
- Shift: When the user presses the Shift key
- Alt: When the user presses the Alt key
- Control: When the user presses the Ctrl key
- Lock: When the user presses the Shift lock
- Double: When the event happens twice in quick succession
- Triple: When the event happens thrice in quick succession
Event types determine the general type of event:
- ButtonPress or Button: Event generated when a mouse button is pressed
- ButtonRelease: Event generated when a mouse button is released
- Enter: Event generated when you move the mouse over a widget
- Leave: Event generated when the mouse pointer leaves a widget
- FocusIn: Event generated when the widget gets the input focus
- FocusOut: Event generated when the widget loses the input focus
- KeyPress or Key: Event generated when a key is pressed
- KeyRelease: Event generated when a key is released
- Motion: Event generated when the mouse is moved
The detail is also optional and serves to indicate the mouse button or key:
- For mouse events, 1 is the left button, 2 is the middle button, and 3 is the right button.
- For keyboard events, it is the key character. Special keys use the key symbol; some common examples are return, Tab, Esc, up, down, right, left, Backspace, and function keys (from F1 to F12).
The callback function takes an event parameter. For mouse events, it has the following attributes:
- x and y: Current mouse position in pixels
- x_root and y_root: Same as x and y, but relative to the left-upper corner of the screen
- num: Mouse button number
For keyboard events, it contains these attributes:
- char: Pressed character code as a string
- keysym: Pressed key symbol
- keycode: Pressed key code
In both cases, the event has the widget attribute, referencing the instance that generated the event, and type, which specifies the event type.
Finally, the add parameter can be '', to replace the callback function if there was a previous binding, or '+' to add the callback and preserve the old ones.
- Node.js 10實戰
- 深入淺出Spring Boot 2.x
- JavaScript 網頁編程從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- 編寫高質量代碼:改善Python程序的91個建議
- MATLAB應用與實驗教程
- Java Web開發技術教程
- 零基礎入門學習Python(第2版)
- 深入理解C指針
- Arduino可穿戴設備開發
- Nagios Core Administration Cookbook(Second Edition)
- Unity Character Animation with Mecanim
- 微課學人工智能Python編程
- Python青少年趣味編程
- Scala Functional Programming Patterns
- 寫給大家看的Midjourney設計書