Make Simple GUIs With the Raspberry Pi Using EasyGUI

Easy Raspberry PI GUI builder

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 a smarter way to show readings from components such as sensors.

This article uses the standard Raspbian operating system.

Make an Interface for Your Project

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

EasyGUI Message Boxes

This article gives an introduction to the library, including some of the most useful options we've found.

Download and Import EasyGUI

Installing the library will be familiar if you've used the apt-get install method. You need an internet connection on your Raspberry Pi, using either a wired Ethernet or Wi-Fi connection.

This command downloads the library and installs it for you. That's all the setup you need to do.

  1. Open a terminal window (the icon of a black screen on your Pi's taskbar) and enter the following command:

    from easygui import *
    import time

    Import EasyGUI

    This version of the import makes coding easier later on. For example, when importing this way, instead of writing easygui.msgbox, you can use msgbox.

  2. In its simplest form, this message box gives 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:

    from easygui import *
    import time
    msg = "Cool box huh?"
    title = "I am a Message Box"
     # Add other commands here

    A message box appears, with I am a Message Box written in the top bar, and Cool box huh? above the button.

    EasyGUI Message Box
  3. Sometimes you'll need the user to confirm an action or choose whether 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 canceled"
     # Add other commands here

    EasyGUI Continue Cancel Box
  4. If the built-in box options don't give you what you need, 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 of 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

    EasyGUI Buttonbox
  5. Buttons are great, but for long lists of options, a choice box makes sense. These boxes list the available options in rows, one after another. An OK and Cancel box is to the side. These are 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)

    EasyGUI Choice Box
  6. Forms are a great way to capture data for your project. EasyGUI has a multenterbox option that allows you to show labeled fields to obtain information.

    It's a case of labeling fields and capturing the input. The example below is for a 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

    EasyGUI Multenterbox
  7. 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).

    Using 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"
      print "No"

    EasyGUI Images

More Advanced Features

There are more box options and examples available depending on how much you want to learn and what your project requires.

EasyGUI Password

Password boxes, code boxes, and file boxes are available, to name a few. It's a versatile library that's easy to pick up in minutes, with some excellent hardware control possibilities as well.

If you'd like to learn how to code other things like Java, HTML, or more, check out the best online coding resources available. 

Was this page helpful?