Easy introduction to macOS App using py2app

Recently, I became interested in creating dashboard with Python.

First option, it’s possible to create the custom tool using a web framework (like Flask or Django) locally, or on a website if deployment (see Gunicorn).

Then the other option is to create software. No Visual Basic, nor Java, nor C ++. I know that even famous applications have been built in Python (Instagram, Spotify, DropBox, Uber, Netflix, ..). I decide after some research to test the creation of a MacOS application.

The purpose of this article: With Python, create a MacOS application using the Tkinter GUI and using py2app.

Tkinter: Python’s de-facto standard GUI (Graphical User Interface) package.

Py2app: Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.


NOTE: For Windows, check Py2exe

Okay, let's create our app!

For this article, it’s not about creating the best app of the year, but getting familiar with the steps in the simplest way:

  1. Create a Python program using tkinter
  2. Create the file
  3. Create the application

1. Create a Python program using tkinter

You coded your Python program with tkinter? Great you are ready for the next step. For me in this exercise, I will use a code provided by You enter two numbers and you choose one of the two buttons to add or subtract.

tkinter import *
class MyWindow:
    def __init__(self, win):
        self.lbl1=Label(win, text='First number')
        self.lbl2=Label(win, text='Second number')
        self.lbl3=Label(win, text='Result')
        self.btn1 = Button(win, text='Add')
        self.btn2=Button(win, text='Subtract'), y=50), y=50), y=100), y=100)
        self.b1=Button(win, text='Add', command=self.add)
        self.b2=Button(win, text='Subtract')
        self.b2.bind('<Button-1>', self.sub), y=150), y=150), y=200), y=200)
    def add(self):
        self.t3.delete(0, 'end')
        self.t3.insert(END, str(result))
    def sub(self, event):
        self.t3.delete(0, 'end')
        self.t3.insert(END, str(result))

window.title('Hello Python')

2. Create the file

Ok, to run our application, we need to create this setup.up file. With a code editor or simply from your Terminal entering this command: py2applet --make--setup

Note: My Python program for exercise is called

Also, make sure you’re in the right directory using Terminal. Ex: cd Desktop/Data\ Work/Exploration/191017\ py2app\ tkinter\ test ( = ‘\’ is needed to handle spaces).

from setuptools import setup
APP = ['']
OPTIONS = {'iconfile':'Sandwich-app.icns',
           'argv_emulation': True,
           'plist': {'PyRuntimeLocations': [
      options={'py2app': OPTIONS},

OPTIONS plist: I had a bug with the application, an internal error, and had to edit PyRuntimeLocations. That’s why I added the plist option with the libpython address (got solution on stackoverflow).

OPTIONS iconfile: Enter the file name of your icon. Icns format (see png to icns).

3. Create the application

You know what ? We finished. Drop your program, icon and in the folder (directory) you want. Select the folder in your Terminal and enter the command: python py2app -A

Yeeah, your app is created. Go to your directory. You now have two new folders (build, and dist). Go to dist. And open your application. Like any application, you can save it to the dock.

That’s all for this article, it was an introduction to creating a macOS application with Python. And from here we should be able to create a beautiful dashboard, with even real-time data!

>>> Tuto tkinter 1
>>> Tuto tkinter 2
>>> Docs on standalone app
>>> Vidéo Py2app tuto
>>> Deploy Flask app
>>> Png to Icns

– – –
And you, is there a Python application that you want to share?
– – –

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *