Create a Mac app using py2app and Python3! !!

At the beginning

This time there is a python program created in previous article, but due to wind rumors, it is easy to make a Python application using py2app, so I am eager to actually make it an application. is. Please enjoy until the end m (_ _) m ✳︎ This article assumes that Python3, Tkinter, and pip3 are installed.

What are the benefits of making an app?

You might be wondering why you need to make an app even though it's easy to run a program. There are two reasons I think. Part 1: Making it into an app makes it easier to share. Part 2: Making it easier to distribute.

Procedure for making an application

step 1

I can't talk about it without a program to make it an app. So let's prepare Python code using Tkinter. Please use this if you like. However, there was a person who posted a cleaner code than me in the comment of Last article, so I think it would be good to refer to the one written by that person.

import tkinter as tk
import random

#Processing when the button is pressed
def dice(event):
    #Generate a random integer and rewrite the contents of label
    value["text"] = random.randint(1,6)


root = tk.Tk()
root.title("Dice.app")
root.geometry('200x150')

value = tk.Label(text="0",font=("",80))
value.pack(fill = 'x', padx=20, side = 'top')

Btn = tk.Button(text='Roll the dice',width=10)
Btn.bind("<Button-1>", dice)
Btn.pack(fill = 'x', padx=20, side = 'top')


root.mainloop()

Step 2

Create a folder called app and put the program file in app earlier. Then issue terminal and type the following command

pip3 install py2app

This completes the installation of py2app. Then go to the app folder in the terminal and type the following command (please replace the dice with the name of your saved file)

py2applet --make-setup dice.py

This command will generate setup.py.

Step 3

Next, prepare the icns image. This image will be the app icon. First, prepare a suitable image. I used the photo of this site. Next, download the app called Image2icon. Create an icns image with this app. Once installed, launch the app and drag and drop the image you want to make into an icon. After that, select ICNS from the export button, specify the save location in app, and wait for ICNS to be created. Screenshot 2021-01-03 0.26.50.png

Step 4

Open setup.py and change it as follows (change the name of your program in APP and the name of your icns file in dice.icns in OPTIONS)

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['dice.py']
DATA_FILES = []
OPTIONS = {'iconfile': 'dice.icns'}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Finally, hit this command on the terminal to finish.

python3 setup.py py2app

The app is now complete. The actual app is stored in the dist of the app folder!

Finally

I was only able to develop apps with Xcode, so I was surprised to be able to create apps in such an instant. Everyone, please try to make an app! !!

✳︎ This article is written by a beginner in the program, so feel free to comment.

Reference site: https://ebi-works.com/python-desktop-app/

Recommended Posts

Create a Mac app using py2app and Python3! !!
Create a web map using Python and GDAL
Create a native GUI app with Py2app and Tkinter
Let's make a Mac app with Tkinter and py2app
Create a python GUI using tkinter
Create a Python environment on Mac (2017/4)
Building a Python environment on a Mac and using Jupyter lab
Create a python environment on your Mac
Create a simple GUI app in Python
[Python] Create a Batch environment using AWS-CDK
Create and deploy a Django (PTVS) app using Azure Table storage
Create a simple scheduled batch using Docker's Python Image and parse-crontab
Create a GIF file using Pillow in Python
Create a Python module
Create a beauty pageant support app using PyLearn2
Create a Python environment
Create a MIDI file in Python using pretty_midi
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
I tried to create a sample to access Salesforce using Python and Bottle
Create a web app that converts PDF to text using Flask and PyPDF2
Create a data collection bot in Python using Selenium
Create a color sensor using a Raspberry Pi and a camera
[Python] Easy Google Translate app using Eel and Googletrans
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
[Python] Create a ValueObject with a complete constructor using dataclasses
Implementing a generator using Python> link> yield and next ()> yield
Build a Python environment on your Mac using pyenv
Create a decent shell and python environment on Windows
Create a company name extractor with python using JCLdic
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Create JIRA tickets using Python
Create a python numpy array
Create a directory with python
Using OpenCV with Python @Mac
Create a shogi game record management app using Django 4 ~ Create View ~
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
[Python] Create a date and time list for a specified period
[Python] Chapter 01-03 About Python (Write and execute a program using PyCharm)
Let's create a PRML diagram with Python, Numpy and matplotlib.
Create code that outputs "A and pretending B" in python
Python: Create a dictionary from a list of keys and values
Shoot time-lapse from a PC camera using Python and OpenCV
Create a virtual environment for python on mac [Very easy]
Create a simple CRUD app using Django's generic class view
I made a Chatbot using LINE Messaging API and Python
I want to create a karaoke sound source by separating instruments and vocals using Python
Building a Python environment on Mac
I made a Line-bot using Python!
Authentication using tweepy-User authentication and application authentication (Python)
Create a DI Container in Python
Drawing a silverstone curve using python
Create a nested dictionary using defaultdict
Create a binary file in Python
Create a python environment on centos
Clustering and visualization using Python and CytoScape
Create a Python general-purpose decorator framework