Please send questions to
st10@humboldt.edu .
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "copyright", "credits" or "license()" for more information.
IDLE 1.2
>>> import sys
>>> sys.path.append("/Users/smtuttle/Humboldt/to-back-up/f06cis180py/180py_lectures/180py_lect10")
>>> # a little TASTE of GUI's and Python...
>>> # first: there are MANY GUI Toolkits for Python, at a variety
>>> # of levels, from simple to sophisticated;
>>> # to find links to MANY,
>>> # go to www.python.org,
>>> # look on the lower right, under "Using Python For...",
>>> # and click on "GUI Development"
>>> # some of the "big names": Tkinter, wxPython, PyQT;
>>> # but some are also supposed to be easier to learn/use:
>>> # EasyGui, PythonCard, Anygui, Boa Constructor
>>> # note: to play with GUI's, run the python LOCALLY on your
>>> # machine; remote-login/ssh doesn't usually work for
>>> # these... 8-)
>>> # let's play a little with EasyGui, whose .py script is
>>> # available from http://www.ferg.org/easygui/
>>> # (it is built atop Tkinter, which tends to come with the
>>> # python standard installation, which means installing
>>> # it can be as easy as copying easygui.py into your
>>> # working directory --- although it would be more general
>>> # to somehow get it into a directory in your PYTHONPATH... 8-) )
>>> from easygui import *
>>> # to get a simple message dialog box:
>>> msgbox("Hello, EasyGui World!")
'OK'
>>> # to get a choice box, where the user's choice is returned
>>> # as its return value:
>>> msg = "What is your favorite flavor?"
>>> title = "Ice Cream Survey"
>>> choices = ["Vanilla", "Chocolate", "Strawberry", "Spam"]
>>> choice = choicebox(msg, title, choices)
>>> choice
'Spam'
>>> # to get a confirmation/cancel box, where user can indicate
>>> # which option and 1 or 0 is returned accordingly:
>>> msg = "Do you want to continue?"
>>> title = "Please confirm"
>>> result = ccbox(msg, title)
>>> result
1
>>> # (and easygui.py uses __name__ to run a test-GUI when executed
>>> # from the command line --- so you can see examples of the
>>> # other components supported:
>>> # cmd-line> python easygui.py
>>> # easyguiEx1.py (posted with this script) includes an example
>>> # from the EasyGui web site, showing how you can build a
>>> # simple GUI application using EasyGui
>>> # (don't worry about the exception below -- that's just how it
>>> # ended after I clicked Cancel in the last displayed component)
>>> import easyguiEx1
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
import easyguiEx1
File "/Users/smtuttle/Humboldt/to-back-up/f06cis180py/180py_lectures/180py_lect10/easyguiEx1.py", line 39, in <module>
sys.exit(0) # user chose Cancel
SystemExit: 0
>>> # this one works from the command line, too
>>> # cmd-line> python easyguiEx1.py
>>> # adding saving the ice-cream survey results to a file...
>>> import easyguiEx2
>>> # wxpython: some examples with a more high-powered GUI toolkit
>>> # check out: http://www.wxpython.org/
>>> # below are some examples from the wxpython site (and these
>>> # scripts are posted along with this session, too)
>>> # a simple frame
>>> import wxpython_ex1
>>> # a simple frame class
>>> import wxpython_ex2
>>> # adding some menu items to a menu in a menubar
>>> import wxpython_ex3
>>> # add a little event handling (some menu items DO something
>>> # when selected...)
>>> import wxpython_ex4
>>> # includes an example of a file-selection dialog box
>>> import wxpython_ex5
>>> # adding some (non-functional) buttons across the bottom
>>> import wxpython_ex6
>>> # an example showing more components: text box, radio buttons,
>>> # check box, and more
>>> import wxpython_ex7