Computer Science 15-112, Fall 2011
Optional Notes: Miscellaneous Tkinter/Python Demos
- (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
-
py2exe
To package your Python program as a Windows
executable (.exe file), check out this
py2exe tutorial (or
this one).
- Possible Future Topics:
- more gui widgets (menus, sliders, scrollbars, etc)
- using Google API’s
-
scripting OpenOffice (or some other apps)
carpe diem
- carpe diem - carpe diem - carpe diem - carpe diem - carpe
diem - carpe diem - carpe diem - carpe diem