Tkinter: Difference between revisions
No edit summary |
|||
| 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 56: | Line 60: | ||
window = tk.Tk() | window = tk.Tk() | ||
animation_loop() | animation_loop() | ||
window.mainloop() | |||
</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() | window.mainloop() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} | ||