I was googling about for a way to make beginning Python more fun. I teach an introductory class on “thinking like a programmer,” and some students are not instantly captivated by the command-line environment. We use the Python Language because it is probably the easiest, least obscure language available. I have been looking for a way to jazz up the class for a while. The concepts are hard enough without having to surmount the students’ feeling that anything on the command line must be dull and old-fashioned. I have looked at several options for GUI-fying Python.
There are a number of IDEs (development environments) and add-ons listed at Python.org. I have looked at several of them with the idea that one or another will make the output more interesting by adding GUI outputs. I do not want the course to devolve into strictly an intro to the details of the programming language. It is challenging to think about things in such a way as to set up problems which can be addressed programatically. Because of the challenge, students often look for less-alien things to focus upon. The nuts and bolts of the programming language are safer ground, so many stay there, and miss the point entirely. You cannot just learn the language and expect it to magically clarify your thinking.
I discovered easygui at http://easygui.sourceforge.net today. It will probably take some more study, but I believe it answers the question well enough. My course is only eleven weeks long, and there just isn’t time to learn a whole programming language in that time. There certainly isn’t time to do it and at the same time cover all the logical basics we are tasked to cover.
Just as a quick example, I ran part of their tutorial, and changed it around to be more entertaining to me. This was extremely simple to figure out and I think it will be much more rewarding for a beginner than what I am currently teaching, where the most graphical element is the turtle module.
1. First you have to go to http://easygui.sourceforge.net and get the newest version of easygui for your version of Python. Because easygui is itself a python script, you should be able to get it to work well regardless of what operating system you are using. I am using Ubuntu 9.10. My editor of choice is Kate. Kate is the default text editor on the KDE desktop environment. If you are on a Windows machine, you can use Idle, which comes bundled with Python, or you might consider getting Notepad++, which is a free high-functionality replacement for notepad.exe.
2. Once you have downloaded and uncompressed easygui, you need to put it somewhere in your PATH where Python can find it. The creator of EasyGUI suggests putting it in your Python site-packages directory.
On Windows, the site-packages folder is typically
For Python version 2.6, for example, the site-packages folder is
The Ubuntu Linux location changed between Python version 2.5 and version 2.6.
- For version 2.5 it is:
- For version 2.6 it is:
Before you can put anything into the dist-packages directory, you will probably have to do:
sudo chmod 755 /usr/local/lib/python2.6/dist-packages
I found I had to use sudo to put the file in the dist-packages directory, even with the directory permissions adjusted. 755 means the owner can read, write to or execute the file, while others can only read and execute. That means I had to be root to move the file into that directory. I used the cp command to place the easygui.py file in the folder.
sudo cp /home/wolf/Documents/Projects/py-proj/easygui.py /usr/local/lib/python2.6/dist-packages
3. Once that is done, you can check the installation by typing the following in the Python Interactive window:
You can also do it this way, if you don’t want to use the dotted notation…
>>>from easygui import *
This will bring up a GUI window with examples of all the possible EasyGUI modules. Using the latter import structure makes your own source code shorter. You will not have to mention the imported module over and over. The former import syntax helps make it plain where the functionality is coming from, but requires a lot of extra typing.
EasyGUI Modules - egdemo() -
4. I copied the first example from the EasyGUI tutorial link and adjusted the indentations to 4 spaces, which is standard on my system. I then changed the dialog’s wording to make it more entertaining. I used triple-quotes ”’ to get the line-breaks where I wanted them, because hard returns inside triple-quotes do not break the string. Inside single or double quotes, a hard return will break the string, and cause a traceback error. Triple-quotes are made by hitting the single-quote key 3 times.
Feel free to change things around, when you run this exercise. You don’t have to use the topic of Ice Cream, for instance…
The first window used to be a “Hello World” window. It appears in the code shown in the Kate window at about line five. I changed it to say more about the program.
1st easyGUI dialog
The second dialog, I created by copying the first and changing the info between the triple-quotes. The code starts on line ten. Notice that the triple-quoted text doesn’t follow the indentation rules at all. It is all the way to the left.
Second EasyGUI Dialog
The third dialog is a list of Ice Cream flavors. The choices apear in the code at around line 18, and are in no particular order. I added a few flavors, also in no particular order. In the outputted dialog they show in alphabetical order, even though the list is not alphabetical.
The next dialog comes from line 23, where a single line in the code can make a whole GUI dialog. It ffirming your choice of flavor.
The final dialog, from line 27 in the code, allows you to escape “Cancel” or run the program again, “Continue.”
This took just a few minutes to do and has given me ideas for all sorts of ways the basic CLI Python exercises could be more fun.