Miscellaneous Python Demos
David Kosbie, 15-110
- (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
See mouseEventsDemo.py
- Mouse Motion Events
mouseMotion
(without button pressed), mousePressed, mouseMoved, mouseReleased, with
left or right button, and with ctrl and shift
See mouseMotionEventsDemo.py
- Key Events
keyPressed, keyReleased with ctrl and shift
See 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_abc(), no redrawAll(), canvas.coords() and canvas.itemconfig()
See deltaGraphicsDemo1.py (without delta graphics)
See deltaGraphicsDemo2.py (with delta graphics)
- Semi-Transparent-Stipple
Tkinter
does not have alpha (semi-transparent) graphics, but it does have
something sort of like that with semi-transparent stipples, which
aren't great but are better than nothing.
See semi-transparent-stipple-demo
- Modules
Use modules to organize large code base
See modulesDemo1.py (no modules)
See modulesDemo2.py with faceDemo.py (with modules)
- Structs
Use "structs" instead of dictionaries to organize "objects"
Extends Modules example
See structsDemo.py with faceDemoWithStruct.py (with modules and structs)
- Classes
Use classes instead of structs or dictionaries to organize "objects" with their "behaviors"
Extends Modules example and Structs example
See classDemo.py with faceDemoWithClass.py (with modules and structs)
- Winsound
(On Windows only!) play sounds synchronously, asynchronously, or in a loop
See winsoundDemo.py
- Simulation
Record a process step-by-step, play back each step in response to keypresses.
See selectionSortSim.py
- Buttons
- Simple Buttons
approach #1: with global canvas
approach #2: with local function and closure
See button-demo1.py
- Buttons in a Row
Simple buttons now in a horizontal row at the top
(using a gridded frame)
(uses same buttons from button-demo1.py)
See button-demo2.py
- Buttons in a Canvas
button in a canvas (rather than next to a canvas)
See button-demo3.py
- Button with an Image
See button-demo4.py
- Dialogs
- Standard Dialogs
tkMessageBox: Info box, warning box, error box, and question box
tkSimpleDialog: Askstring box
See dialogs-demo1.py
- Modal Password Dialog
modal dialog, text input field, and hidden password
See dialogs-demo2.py
- Possible Future Topics:
- exe packaging (http://www.py2exe.org/index.cgi/Tutorial)
- more gui widgets (menus, sliders, scrollbars, etc)
- shell scripting
- writing applets (web-browser-based programs)
- writing web-based client-server apps
- using Google API’s
- scripting OpenOffice (or some other apps)
- other topics?