Adding a graphical user interface (GUI) to your Raspberry Pi project is a great way to include a screen for data entry, on-screen buttons for controls or even just a smarter way to show readings from components such as sensors.

01 of 10 Make an Interface for Your Project Several different GUI methods are available for the Raspberry Pi. However, most have a steep learning curve. The Tkinter Python interface may be the default "go-to" option for most, but beginners can struggle with its complexity. Similarly, the PyGame library offers possibilities for making impressive interfaces but may be surplus to requirements. If you're looking for a quick and straightforward interface for your project, EasyGUI could be the answer. What it lacks in graphical beauty it more than makes up for in its simplicity and ease of use. This article will give you an introduction to the library, including some of the most useful options we've found.

02 of 10 Downloading and Importing EasyGUI For this article, we're using the standard Raspbian operating system. Installing the library will be a familiar process to most, using the "apt-get install" method. You'll need an internet connection on your Raspberry Pi, using either a wired Ethernet or WiFi connection. Open a terminal window (the icon of a black screen on your Pi's taskbar) and enter the following command: This command will download the library and install it for you, and that's all the setup you need to do.

03 of 10 Import EasyGUI EasyGUI needs to be imported into a script before you can use its functions. This is achieved by entering a single line at the top of your script and is the same regardless of which EasyGUI interface options you use. Create a new script by entering the following command in your terminal window: A blank screen will appear — this is your empty file (nano is simply the name of a text editor). To import EasyGUI into your script, enter the following line: We use this specific version of the import to make coding even easier later on. For example, when importing this way, instead of having to write easygui.msgbox we can simply use msgbox. Now let's cover some of the essential interface options within EasyGUI.

04 of 10 Basic Message Box This "message box," in its simplest form, gives the user a line of text and a single button to click. Here's an example to try. Enter the following line after your import line, and save using Ctrl+X: To run the script, use the following command: from easygui import * import time msg = "Cool box huh?" title = "I am a Message Box" # Add other commands here You should see a message box appear, with I am a Message Box written in the top bar, and Cool box huh? above the button.

05 of 10 Continue or Cancel Box Sometimes you will need the user to confirm an action or choose whether or not to continue. The "ccbox" box offers the same line of text as the primary message box above, but provides two buttons — Continue and Cancel. Here's an example of one in use, with the continue and cancel buttons printing to the terminal. You could change the action after each button press to do whatever you like: from easygui import * import time msg = "Would you like to continue?" title = "Continue?" if ccbox(msg, title): # show a Continue/Cancel dialog print "User selected continue" # Add other commands here else: # user chose Cancel print "User cancelled" # Add other commands here

06 of 10 Custom Button Box If the built-in box options aren't quite giving you what you need, you can create a custom button box using the "buttonbox" feature. This is great if you have more options that need covering, or perhaps are controlling a number of LEDs or other components with the UI. Here's an example selecting sauce for an order: from easygui import * import time msg = "Which sauce would you like?" choices = ["Mild","Hot","Extra Hot"] reply = buttonbox(msg, choices=choices) if reply == "Mild": print reply if reply == "Hot": print reply if reply == "Extra Hot": print reply





07 of 10 Choice Box Buttons are great, but for long lists of options, a "choice box" makes a lot of sense. These boxes list the available options in rows one after another. An OK and Cancel box is to the side. They're reasonably smart, sorting the options alphabetically and also allowing you to press a key to jump to the first option of that letter. Here's an example showing ten names, which you can see has been sorted in the screenshot. from easygui import * import time msg ="Who let the dogs out?" title = "Missing Dogs" choices = ["Alex", "Cat", "Michael", "James", "Albert", "Phil", "Yasmin", "Frank", "Tim", "Hannah"] choice = choicebox(msg, title, choices)

08 of 10 Data Entry Box Forms are a great way to capture data for your project, and EasyGUI has a 'multenterbox' option that allows you to show labeled fields to obtain information. Once again it's a case of labeling fields and merely capturing the input. We 've made an example below for a very simple gym membership sign-up form. There are options to add validation and other advanced features, which the EasyGUI website covers in detail. from easygui import * import time msg = "Member Information" title = "Gym Membership Form" fieldNames = ["First Name","Surname","Age","Weight"] fieldValues = [] # the starting values fieldValues = multenterbox(msg,title, fieldNames) print fieldValues





09 of 10 Adding Images You can add images to your EasyGUI interfaces by including a minimal amount of code. Save an image to your Raspberry Pi in the same directory as your EasyGUI script and make a note of the file name and extension (for example, image1.png). Let's use the button box as an example: from easygui import * import time image = "RaspberryPi.jpg" msg = "Is this a Raspberry Pi?" choices = ["Yes","No"] reply = buttonbox(msg, image=image, choices=choices) if reply == "Yes": print "Yes" else: print "No"



