Create a Simple Python GUI With These Open Source Projects

Not every programmer is a designer. In fact, a lot of great engineers are lost when it comes to effective user interface design. Specialization can be a good thing, despite the recent trend of “full-stackifying” every single developer role. Being really good at writing server code and dealing with the specific problem set to solve in that realm is important, and shouldn’t necessarily translate to the frontend. So, what if you fall into this category but you need a quick GUI?
If you’re prototyping a new application that would benefit from a basic UI bolted on, it might feel like your options are limited. In some cases it feels like you either have to build the entire thing from scratch or get someone else to do it (which might not be an option at all). In the world of Python your options are more than just binary. The Python community has a world of drag-and-drop and low-code UI editors that you can build fully functioning graphical user interfaces with.
In this article we’re going to examine some of the options available for rapid prototyping of a GUI for Python applications. This means that most of these solutions won’t be very code-heavy and favor a straightforward point-and-click approach. If you’re focused on function over form, but don’t want to completely eschew a modern UI these are perfect avenues to explore. Let’s take a look.
Pygubu

Pygubu is a suite of tools that make developing a UI using the tkinter library much easier. There are two major components, the primary core module called pygubu
and the graphical design application pygubu-designer
. The designer allows you to create interfaces using the drag-and-drop method and generates XML as the final output.
The workflow using Pygubu is pretty straightforward and simple. You run the designer application and setup your GUI layout using frames, buttons, inputs and other widgets. Once you’re happy with the layout you can generate the final XML as a “.ui” file. The “.ui” file can be passed to Pygubu in your underlying application code using pygubu.Builder()
from the core Pygubu module.
Overall, creating a simple UI with Pygubu was super easy and I liked the fact that the designer was separate from the core application code. This gives a nice logical separation between setting a layout and plumbing all the functionality together behind the scenes. Editing a layout after the fact to make small tweaks was also incredibly easy since its just basic XML.
For more information on getting up and running with Pygubu, check out: https://github.com/alejandroautalan/pygubu
PAGE

PAGE is another wrapper for the Tkinter system and provides a similar WYSIWYG interface to that of Pygubu. PAGE stands for Python Automatic GUI Generator and although this library is rather old, it still gets the job done quickly and effectively.
Just like Pygubu, you can spin up a new layout easily by running the page
application and organizing widgets on window frames. There are some slight differences in how PAGE handles the underlying files. Instead of saving the layout as XML it saves as a “.tk” file which is directly readable by Tkinter, but much less user friendly to edit directly after the fact.
There is also no core module provided by PAGE. Once you have generated your layout as a “.tk” file you simply use it directly with the Python Tkinter module. This means you’ll have to already be familiar with how Tkinter works to implement it in your underlying application code. If you’ve never used Tkinter before, there is a great step-by-step guide by Steffy Lo available here.
Head over to the PAGE documentation site for more info: http://page.sourceforge.net/html/index.html
Gooey

Gooey is the epitome of simplicity. This library doesn’t come with any fancy layout editors, in fact you barely have to spend any time away from your underlying application code. Gooey is designed to be simple to implement, but also simple to use. Think of it as a wrapper for things like installers, or control panel apps. Any application where you have to select a few options and kick off a long-running process is right in Gooey’s wheelhouse. Plus it works across different platforms so you can deploy the same app to multiple operating systems quickly.
Gooey is incredibly straightforward to use. All you need to do is install the module pip3 install Gooey
and then add a few basic decorators to your code. For example, to bolt Gooey on to an existing function, just add the following decorator and setup an argument parser:
@Gooey
def main():
GooeyParser(description='test').parse_args()main()
If you run the code above with Gooey you’ll get a pre-built window layout ready to go. This is a huge step forward for being able to rapidly develop applications that require multi-step installations or processes. This is also quite a different approach from the other GUI libraries and aims to make things a lot easier on both developers and users.
If you’re interested in integrating Gooey into your own application, I highly suggest checking out Brunna Villar’s piece to get started: Building an easy GUI (graphical user interface) with Python.
For even more Gooey goodness, check out the documentation here: https://github.com/chriskiehl/Gooey#quick-start
PySimpleGUI

PySimpleGUI is… well… simple. That’s a good thing. Generating the UI pictured above only took a few lines of code and a single module installation. The layout itself is a “list of lists” with an exceptionally pragmatic widget interface. Just like Gooey, it doesn’t require you to work with a separate visual layout builder or generate UI files for later use.
import PySimpleGUI as guilayout = [
[gui.Text('hello')],
[gui.Button('Ok')]
]window = gui.Window('My window', layout)event, vals = window.read()window.close()
One of the primary differences between PySimpleGUI and Gooey is that it doesn’t require the use of decorators on existing functions. You can instantiate a new window and define the exact parameters of it without ever attaching it to existing code. Depending on your workflow this might be the better option if you’re after a more procedural approach to generating a GUI.
PySimpleGUI also has a very active community and a ton of examples to show the power of this awesome library. Head over to their repository on GitHub to get inspired by some interesting design ideas: https://github.com/PySimpleGUI/PySimpleGUI
Thanks for reading! I hope these tools provide an easier path towards building quick and easy graphical interfaces for your applications. If you enjoyed this article and want even more Python fun, check out: Handy Python Snippets for Cleaner Code.