Tkinter: Difference between revisions

From David's Wiki
No edit summary
 
Line 80: Line 80:
</syntaxhighlight>
</syntaxhighlight>
}}
}}
;Notes
* Use <code><KeyRelease></code> to detect key releases.

Latest revision as of 18:46, 1 February 2021

Tkinter is a Python API for the Tk GUI. It is built into the Python standard library and is cross platform.

Layout

tk.Frame

You can use tk.Frame as general containers.

Images

To display an image, create a tk.Canvas and then use canvsa.create_image.

Example
Notes
  • Make sure the ImageTk.PhotoImage does not get garbage collected.

Animation Loop

For interactive applications, you may want an animation loop called every few milliseconds.
To accomplish this, use .after.

Example

Keypress

To just detect key presses:

Example
Notes
  • Use <KeyRelease> to detect key releases.