CMU 15-112: Fundamentals of Programming and Computer Science
Class Notes: Miscellaneous Tkinter/Python Demos
For convenience, tkinter-demos.zip contains all the examples from below.
- (Non)-Resizable Windows
non-resizable window and resizable window (with sizeChanged)
See resizableDemo.py and nonResizableDemo.py - Mouse Events
mousePressed, mouseMoved, mouseReleased, with left or right button, and with ctrl and shift, and mouseMotion (without button pressed)
See mouseEventsDemo.py - Key Events
keyPressed, keyReleased with ctrl and shift
keyEventsDemo.py - Images
view in canvas, read from file, read from the web, with transparent pixels, get size, resize (zoom and subsample), read/write pixels, base64 encoding (create from file, view as image)
Requires: sampleImage1.gif
See imagesDemo1.py (read from file)
See imagesDemo2.py (read from web)
See imagesDemo3a.py and imagesDemo3b.py, (write base64, read from base64)
See imagesDemo4.py (read/write pixels)
- Delta (Efficient) Graphics
Return values from create_shape(), no redrawAll(), canvas.coords() and canvas.itemconfig()
See deltaGraphicsDemo1.py (without delta graphics)
See deltaGraphicsDemo2.py (with delta graphics)
- Buttons
- Simple Buttons
See button-demo1.py
- Buttons in a Row
Simple buttons now in a horizontal row at the top or bottom
(using a gridded frame)
(uses same buttons from button-demo1.py)
See button-demo2.py
- Buttons with an Image
Requires: button.gif
See button-demo3.py
- Simple Buttons
- Dialogs
- Standard Dialogs
messagebox: Info box, warning box, error box, and question box
simpledialog: Askstring box
See dialogs-demo1.py
- Modal Password Dialog
modal dialog, text input field, and hidden password
See dialogs-demo2.py
- Standard Dialogs
- py2exe
To package your Python program as an executable app (.exe file in Windows, similar executable on a Mac) that does not require Python to be installed on the client machine, check out py2exe for windows (tutorial here) or py2app for Macs (tutorial here). Alternatively, cx_freeze also does something similar but cross-platform for both Windows and Macs.