[PYTHON] Let's make a Mac app with Tkinter and py2app

I want to make an app for Mac.

We received a consultation from a store that helps us with the production of web pages, etc., about how to put together the order details of an online shop that receives pre-orders mainly online due to the influence of Corona. It's okay to put it together in Excel, but I thought I could make a simple app, so I decided to make it while investigating.  Tkinter https://python-textbok.readthedocs.io/en/1.0/Introduction_to_GUI_Programming.html Copy and paste the Introduction to GUI Program and run it. By the way, it seems that Tkinter is often included in python, so if you are developing on Mac, you do not need to install it. Try running the calculator sample program at the end of this page. Screen Shot 2020-05-04 at 7.02.38.png The + and-that should have appeared do not appear. I tried various things, but tkinter and py2app described later seem to be very susceptible to the influence of the python version and the installation source, so I tried changing the installation source such as pyenv and miniconda, but after all I updated the OS to Catalina And probably succeeded with Python 3.8.2 (I'm sorry if it's different!) And virtualenv which were included in the genuine product. It would be a good article to record the failure record of this area, but I have not recorded it properly, so I will record it the next time I do something. Screen Shot 2020-05-04 at 7.43.23.png case being settled. Now, let's look at the sample program and change the necessary parts.

work

Since it is a program that reads csv files and outputs the aggregated results, I decided to create only the side because the interface is good with the part that displays the file name, the directory call button, and the execute button. A simple task of rewriting the class defined in the sample to your own class and pressing one button. Screen Shot 2020-05-04 at 7.58.26.png This looks good. Next, let's make the contents. I referred to the qiita articles of here and here. (Because I am a beginner, please let me know if there is a better way to quote.) For tkinter's filedialog, I referred to this tutorial. Data organization reads the usual Pandas. Website CSV, creates a dataframe subset of product names, and aggregates them.

#List only unique values
self.itemlist=df["Item's Name"].unique()
#Calculate total number from subset data frames
result={}
for item in self.itemlist:
  tempdf=df.loc[df["Item's Name"]==item]
  sumqty=tempdf["Qty"].sum()
  result[item]=sumqty

Binary creation for Mac

Create a binary for Mac. I tried using py2app by referring to this site, but my Mac crashed, the app couldn't be opened, and so on. To clear various dependency problems here, I put the necessary libraries in the virtualenv environment into virtualenv with pip (I think it was only pandas and py2app this time), and finally succeeded in creating the application.

The usage of py2app itself is very easy

py2applet --make-setup test.py
python setup.py py2app

You can do it with just this. Dependent libraries don't seem to work unless they are properly separated by virtualenv. In this way, the first application life was finally completed. Even if the code could be done in one day, it took two more days to make it an app lol I'm sorry that the tone has changed. Let's meet again.

Recommended Posts

Let's make a Mac app with Tkinter and py2app
Create a native GUI app with Py2app and Tkinter
Create a Mac app using py2app and Python3! !!
Let's make dice with tkinter
Let's make a simple game with Python 3 and iPhone
Let's make a nervous breakdown app with Vue.js and Django-Rest-Framework [Part 2] ~ Vue setup ~
Let's make a nervous breakdown app with Vue.js and Django-Rest-Framework [Part 1] ~ Django setup ~
Let's make a GUI with python.
Let's make a breakout with wxPython
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a Mac menu bar resident weather app with rumps!
Let's make a voice slowly with Python
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Let's replace UWSC with Python (5) Let's make a Robot
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 3] ~ Implementation of nervous breakdown ~
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 6] ~ User Authentication 2 ~
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 5] ~ User authentication ~
Let's make a Makefile and build it (super beginner)
[Practice] Make a Watson app with Python! # 1 [Language discrimination]
[Let's play with Python] Make a household account book
Let's make a spherical grid with Rhinoceros / Grasshopper / GHPython
[Super easy] Let's make a LINE BOT with Python.
Let's make an app that can search similar images with Python and Flask Part1
Let's make an app that can search similar images with Python and Flask Part2
Programming with Python and Tkinter
Let's make a Discord Bot.
Working with tkinter and mouse
Let's make Othello with wxPython
Make a fortune with Python
Let's make a rock-paper-scissors game
Make a fire with kdeplot
Let's make a websocket client with Python. (Access token authentication)
[Practice] Make a Watson app with Python! # 3 [Natural language classification]
Let's create a PRML diagram with Python, Numpy and matplotlib.
Make a 2D RPG with Ren'Py (3) -Items and Tool Shop
I tried to make GUI tic-tac-toe with Python and Tkinter
Let's make a diagram that can be clicked with IPython
Make a BLE thermometer and get the temperature with Pythonista3
Let's make a remote rumba [Hardware]
Let's make a WEB application for phone book with flask Part 1
Let's make a remote rumba [Software]
Let's create a tic-tac-toe AI with Pylearn 2-Save and load models-
Make a sound with Jupyter notebook
Let's make a cycle computer with Raspberry Pi Zero (W, WH)
Let's make a spot sale service 2
Build a Python environment on your Mac with Anaconda and PyCharm
HTTPS with Django and Let's Encrypt
Let's make a WEB application for phone book with flask Part 2
How to make a surveillance camera (Security Camera) with Opencv and Python
Let's make a spot sale service 1
Make a Spinbox that can be displayed in Binary with Tkinter
Let's make Othello AI with Chainer-Part 1-
Make let and let's one-line programming
Easy GUI app with Tkinter Text
Creating a simple app with flask
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4