Tkinter: Difference between revisions
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Tkinter is a Python API for the Tk GUI. It is built into the Python standard library and is cross platform. | Tkinter is a Python API for the Tk GUI. It is built into the Python standard library and is cross platform. | ||
==Layout== | |||
===<code>tk.Frame</code>=== | |||
You can use <code>tk.Frame</code> as general containers. | |||
==Images== | ==Images== | ||
Line 31: | Line 35: | ||
}} | }} | ||
;Notes | ;Notes | ||
* Make sure the <code> | * Make sure the <code>ImageTk.PhotoImage</code> does not get garbage collected. | ||
==Animation Loop== | ==Animation Loop== | ||
Line 59: | Line 63: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} | ||
==Keypress== | |||
To just detect key presses: | |||
{{ hidden | Example | | |||
<syntaxhighlight lang="python"> | |||
import tkinter as tk | |||
def key_pressed(event): | |||
print("Key pressed", event.char, event.keysym) | |||
window = tk.Tk() | |||
window.bind("<Key>", key_pressed) | |||
window.mainloop() | |||
</syntaxhighlight> | |||
}} | |||
;Notes | |||
* Use <code><KeyRelease></code> to detect key releases. |