Python is active in the fields of machine learning and data science, but its GUI is also excellent, and the kivy used this time can be built to create applications that work on desktop, Android, and iOS.
This time, I will give a brief explanation for those who have never made an application but know Python to some extent. Also as a memorandum for myself. ..
One of the Python libraries that makes it easy to create a GUI (graphical user interface: not a black console screen).
Japanese Reference also exists, and it is a library that is still under development.
As for how to use it, many other people have written easy-to-understand and polite articles, so I will omit it here. This time, we will proceed on the assumption that it will be an application.
kivy-ios I will clone it from the GitHub here page.
__ Support for iOS 13 __ From iOS 13, there seems to be a big change in the Objective-C language, and for a while this kivy-ios stopped working. As of December 28, 2019, the pull request of the corrected part has been merged and is ready for use.
Objective-C iOS 13.0 breaking changes #53
Start building the app immediately. kivy-ios First, install the dependent packages to run kivy-ios.
xcode-select --install
brew install autoconf automake libtool pkg-config
brew link libtool
pip3 install cython==0.28.1
In the cloned directory,
pip3 install -r requirements.txt
To execute. Now you are ready to use kivy-ios.
After this, we will embed the python program in the app, so we need to build python itself for the app. The command is:
python3 toolchain.py build python3 kivy
This process took about an hour in my environment (Mac book Pro 2016). Sweat
This time it's a tutorial, so let's make a stopwatch. As for the contents, create one button and output the difference between the time when the button is pressed the first time datetime.datetime.now ()
and the time when the button is pressed the second time.
main.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from datetime import datetime
class MainWindow(Widget):
button_text = StringProperty("Push Button!!")
timer_text = StringProperty("START")
def __init__(self, **kwargs):
super(MainWindow, self).__init__(**kwargs)
self.timer_check = False
self.timer_before = 0
def push_button(self):
if not self.timer_check:
self.timer_before = datetime.now()
self.timer_check = True
self.button_text = "STOP"
self.timer_text = "Running..."
else:
self.timer_check = False
self.button_text = "START"
self.timer_text = str(datetime.now() - self.timer_before)
class StopWatchApp(App):
def __init__(self, **kwargs):
super(StopWatchApp, self).__init__(**kwargs)
def build(self):
return MainWindow()
if __name__ == '__main__':
StopWatchApp().run()
stopwatch.kv
MainWindow:
<MainWindow>:
BoxLayout:
orientation: "vertical"
size: root.size
Label:
text: root.timer_text
Button:
text: root.button_text
on_press: root.push_button()
It looks really cheap, but I was able to do it. At this time, save the Python script as main.py
. Put the created py file and kv file in an appropriate directory. (This time I saved it in a directory called stopwatch
.)
If you're enrolled in the Apple Developer Program, that's okay, but you'll have to pay an annual fee to actually publish your app to the store. However, even if it is free, you can only build the actual machine, so please set it referring to the following article.
[Xcode] How much can you do with a free real machine build
__ Free real machine build __ The profile is valid for __7 days __. After this, you will not be able to start from the iPhone, so you need to transfer to the actual device again.
Type the command according to the following command syntax.
python3 toolchain.py create <title> <app_directory>
This time, I put a directory called stopwatch
in the directory where kivy-ios-master
is located, so
python3 kivy-ios-master/toolchain.py create StopWatch ./stopwatch
It will be. Then, a directory called stopwatch-ios
will be created in the same directory, so open the XCode project stopwatch.xcodeproj
inside.
Select the provisioning profile you set earlier from the project settings, select the connected iPhone from the terminal selection screen on the upper left, and press the triangle button to build. At this time, if you have a passcode on your iPhone, you need to cancel it and leave it on the home screen.
Also, the first build will start automatically, but it won't start because the profile is not official. You need to authenticate from the iPhone's Settings> General> Device Administrator
.
It seems that the build was successful. I'm happy.
I'm sorry that the image quality is so bad that I'm dead because I took it with a webcam.
I never thought it would be so easy to create an app. What kind of head structure does a person who comes up with such a library have? Lol
I want to make various things again.
Recommended Posts