Home  >  Article  >  Backend Development  >  Can python be used as an app?

Can python be used as an app?

(*-*)浩
(*-*)浩Original
2019-06-26 13:07:5613428browse

Although the python language is very versatile, it is still a bit wrong to use it to develop apps. Therefore, apps developed with python should be used as coding exercises or for self-entertainment. In addition, the current modules in this area are not special. It is mature and has many bugs. All in all, I advise you not to enter it lightly.

Can python be used as an app?

Preparation work (Recommended study: Python video tutorial)

Required for developing apps using python A module of python – kivy, kivy is an open source, cross-platform Python development framework for developing innovative applications. In short, this is a python desktop program development framework (similar to wxpython and other modules). The powerful thing is that kivy supports linux, mac, windows, android, and ios platforms. This is why this module is needed to develop apps.

Although kivy is cross-platform, if you want to use python code on different platforms, you also need to package the python code into an executable program for the corresponding platform. Fortunately, there is a packaging tool project under the kivy project – buildozer , this is the officially recommended packaging tool because it is relatively simple and has a high degree of automation. Other projects such as python-for-android can also play a similar role and will not be introduced here.

Develop the first python app with kivy

After installing kivy, you can develop the app program. Here is a demonstration of the hello-world program, about the more complex usage of kivy. It is not the focus of this article and will be introduced later.

1) Create a main.py file and write:

#! -*- coding:utf-8 -*-
from kivy.app import App
class HelloApp(App):
    pass
if __name__ == '__main__':
    HelloApp().run()

2) Create a hello.kv file and write:

Label:
    text: 'Hello, World! I am nMask'

Simple description: main.py It is the entry function and defines a HelloApp class, which inherits kivy.app; the hello.kv file is a kivy program, which is equivalent to defining the interface style, etc. The naming rule of this file is that the class name is lowercase and app is removed.

Run the first python app

python main.py

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of Can python be used as an app?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn