EasyGUI - an even simpler Graphical User Interface

I just came across a module called easygui  http://easygui.sourceforge.net/, which seems to be a wrapper around TkInter. Too be fair it seems to mainly (only?) provide dialog boxes, but these can be very useful to quickly get some input from the user and do some processing with it and it looks a lot nicer than using raw_input().

Here's the example code for creating a multi-value enter box (I personally would not have chosen a credit card application, but anyway...)  The names (labels) for the five input fields are simply stored in a list (fieldNames), the input fields' values are returned in another list (fieldValues). When called, multenterbox() pops up the dialog box shown above and waits until the user hits OK or Cancel (for which it'll return None): 
from easygui import *
msg = "Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name","Street Address","City","State","ZipCode"]
fieldValues = multenterbox(msg,title, fieldNames)
print fieldValues
Here's the tutorial with examples of many more kinds of dialogs: http://easygui.sourceforge.net/current_version/tutorial/index.html

Esygui consists of only a single .py file  so it's work on Windows and Mac and the installation consists simply of moving the easygui.py file into your site-packages folder.

"Installation"
Download the zip file and unzip it, this will give you a folder (something like easygui_v0.93, containing easygui.py, documentation, examples, etc.). Look inside that asygui_v0.93 folder and copy only the easygui.py file into your site-packages folder.

On Windows this is usually C:\pythonXX\Lib\site-packages (where XX is your python version, e.g. 26 for Python 2.6). Do not simply copy the entire unzipped easygui folder into your site-packages folder, only easygui.py.

On Mac the site-packages folder could be /Library/Python/2.6/site-packages, on my Mac it's /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages, however. To find out, open a terminal (Terminal.app) and type:

set | grep PYTHONPATH

That should print your site-packages folder. (set is a bashell command that generates a list of all environment variables and their values, | is the UNIX "pipe" symbol that  pipes that list into the grep command, which will only print PYTHONPATH and it's path), for me that's:

PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

In Finder, make your way to that folder and copy easygui.py into it (again, just the .py file, not the entire folder...). Now you're set to use easygui - have fun!

No comments:

Search This Blog