Writing a GUI Application with Python and Py2App

Matt Harzewski
The Startup
Published in
9 min readJun 12, 2020

--

Have you ever wanted to whip up a quick and dirty graphical interface for a utility you made, and give your Python script a first-class presence in your Dock? Apple doesn’t make it easy to give programs the graphical treatment without breaking out Swift/Objective-C and learning the whole Cocoa ecosystem. Fortunately, there is an easier way…

I’m the conflicted sort of computer user. One half of me loves the text-based world of terminal software, from piping data around in Bash to editing text in vim when it suits me. I’ve never touched a GUI when using Git, and I dabble in tiling window managers when I use Linux. The other half appreciates quality GUIs…and I’m certainly picky about them. I’ve been a fan of the Macintosh ecosystem since it was a minor fringe thing, and firmly believe that applications should strictly follow Apple’s Human Interface Guidelines. Applications should look and act like Mac apps first and be their own thing second.

Obviously I loathe Electron and its ilk. If I wanted my apps to feel like something other than Cocoa apps, I wouldn’t be using a Mac, would I? Over-designed web pages in a wrapper aren’t my cup of tea at all. That digression could be an article in itself, so I will spare you the ranting.

So here’s the scenario: we, as programmers, inevitably automate irritating tasks and throw together scripts that make life easier. While we may be comfortable with popping a terminal open and running something with the old python3 somefile.py, most people are not. If I want to help a family member or coworker or local volunteer organization out with a small bespoke bit of software, how can I make it accessible to them?

The two important things that we need are:

  1. A GUI, so the user can click fancy things instead of supplying arguments to an arcane terminal program.
  2. For the app to live in the Dock and be launch-able with a single click, like any other application.

The second point is actually the easiest problem to solve, surprisingly. There are tools out there that can automate the process of packaging programs into application bundles so the OS will treat them as we expect. Py2App is what we will be using here. For Windows users, there is a counterpart called Py2Exe. They…

--

--