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.
  1. (Non)-Resizable Windows
    non-resizable window and resizable window (with sizeChanged)
    See resizableDemo.py and nonResizableDemo.py

  2. Mouse Events
    mousePressed, mouseMoved, mouseReleased, with left or right button, and with ctrl and shift, and mouseMotion (without button pressed)
    See mouseEventsDemo.py

  3. Key Events
    keyPressed, keyReleased with ctrl and shift
    keyEventsDemo.py

  4. 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)

  5. 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)

  6. Buttons

  7. 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

  8. 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.