{"id":17089,"date":"2023-12-15T11:06:37","date_gmt":"2023-12-15T03:06:37","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=17089"},"modified":"2023-12-15T11:06:37","modified_gmt":"2023-12-15T03:06:37","slug":"python%e5%8f%af%e4%bb%a5%e5%bc%80%e5%8f%91%e5%ae%89%e5%8d%93app","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/17089\/","title":{"rendered":"python\u53ef\u4ee5\u5f00\u53d1\u5b89\u5353app"},"content":{"rendered":"

\u5982\u4f55\u4f7f\u7528Python\u5f00\u53d1\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\uff08app\uff09<\/p>\n

Python\u662f\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u56e0\u5176\u7b80\u6d01\u7684\u8bed\u6cd5\u89c4\u5219\u548c\u5f3a\u5927\u7684\u5e93\u652f\u6301\u5e7f\u53d7\u7a0b\u5e8f\u5458\u559c\u7231\u3002\u7136\u800cPython\u5728\u5b89\u5353\u5e94\u7528\u5f00\u53d1\u65b9\u9762\u7684\u5e94\u7528\u5e76\u4e0d\u50cfJava\u6216Kotlin\u90a3\u4e48\u666e\u904d\u3002\u5c3d\u7ba1\u5982\u6b64\uff0c\u8fd8\u662f\u6709\u4e00\u4e9b\u4f18\u79c0\u7684\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4f7f\u7528Python\u5f00\u53d1\u5b89\u5353\u5e94\u7528\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u7f16\u5199\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

1. Kivy<\/p>\n

Kivy \u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u8de8\u5e73\u53f0\u7684\u81ea\u7136\u7528\u6237\u754c\u9762\uff08NUIs\uff09\u7684 Python \u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5728 Windows, Mac OS, Linux, Android \u548c iOS \u5e73\u53f0\u4e0a\u8fd0\u884c\u3002Kivy\u5177\u6709\u53ef\u6269\u5c55\u6027\uff0c\u652f\u6301\u591a\u70b9\u89e6\u63a7\u7b49\u591a\u79cd\u8f93\u5165\u8bbe\u5907\u3002\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ec4\u4ef6\u5e93\u548c\u4e13\u95e8\u7684\u8bed\u8a00\uff08Kv\u8bed\u8a00\uff09\u6765\u5b9a\u4e49UI\u5e03\u5c40\uff0c\u53ef\u4ee5\u7528\u8f83\u5c11\u7684\u4ee3\u7801\u91cf\u5b9e\u73b0\u590d\u6742\u7684UI\u8bbe\u8ba1\u3002Kivy\u662f\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u514d\u8d39\u4f7f\u7528\u5b83\u6765\u5f00\u53d1\u5546\u4e1a\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

– \u5b89\u88c5Kivy<\/p>\n

\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5Kivy\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

pip install kivy<\/p>\n

“`<\/p>\n

– \u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5b89\u5353\u5e94\u7528<\/p>\n

\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a main.py \u7684\u6587\u4ef6\uff0c\u7136\u540e\u952e\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`python<\/p>\n

from kivy.app import App<\/p>\n

from kivy.uix.label import Label<\/p>\n

class MyApp(App):<\/p>\n

def build(self):<\/p>\n

return Label(text=’Hello World!’)<\/p>\n

if __na\u5b89\u5353app<\/a>me__ == ‘__main__’:<\/p>\n

MyApp().run()<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u7b80\u5355\u7684\u5e94\u7528\u7a0b\u5e8f\u4f1a\u663e\u793a\u4e00\u4e2a\u5305\u542b”Hello World!”\u6587\u672c\u7684\u6807\u7b7e\u5b89\u5353APP\u5f00\u53d1<\/a>\u3002\u8fd0\u884c\u4ee3\u7801\u540e\uff0c\u5c06\u5728\u684c\u9762\u73af\u5883\u4e2d\u542f\u52a8\u4e00\u4e2a\u7a97\u53e3\u663e\u793a\u7ed3\u679c\u3002<\/p>\n

2. Buildozer<\/p>\n

\u8981\u5c06Kivy\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u5230\u5b89\u5353\u5e73\u53f0\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u540d\u4e3aBuildozer\u7684\u5de5\u5177\u3002Buildozer\u53ef\u4ee5\u8f7b\u677e\u5730\u4e3aAndroid\u548ciOS\u6253\u5305Kivy\u5e94\u7528\u7a0b\u5e8f\u3002\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u4e3aAndroid APK\u6587\u4ef6\u7684\u8fc7\u7a0b\u79f0\u4e3a\u201c\u6253\u5305\u201d\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

– \u5b89\u88c5Buildozer<\/p>\n

\u5728Linux\u6216macOS\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Buildozer\uff1a<\/p>\n

“`<\/p>\n

pip install buildozer<\/p>\n

“`<\/p>\n

\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fWindows\u7cfb\u7edf\uff0c\u9700\u8981\u53c2\u8003\u5b98\u65b9\u6587\u6863\u5b89\u88c5\u76f8\u5e94\u7684\u5b50\u7cfb\u7edf\u6216\u865a\u62df\u73af\u5883\u3002<\/p>\n

– \u4e3a\u5e94\u7528\u521b\u5efaSpec\u6587\u4ef6<\/p>\n

\u5728\u5e94\u7528\u7a0b\u5e8f\u76ee\u5f55\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521d\u59cb\u5316Buildozer\uff1a<\/p>\n

“`<\/p>\n

buildozer init<\/p>\n

“`<\/p>\n

\u6267\u884c\u547d\u4ee4\u540e\uff0c\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a`buildozer.spec`\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u5305\u542b\u4e86\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6240\u9700\u7684\u8bbe\u7f6e\uff0c\u4f8b\u5982\u5e94\u7528\u540d\u79f0\u3001\u7248\u672c\u3001\u4f5c\u8005\u7b49\u3002\u6309\u9700\u4fee\u6539\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n

– \u6253\u5305\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u73b0\u5728\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1\u548c\u6253\u5305\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

buildozer android debug deploy run<\/p>\n

“`<\/p>\n

\u6b64\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a”appname-version.apk”\u7684\u6587\u4ef6\uff0c\u8fd9\u662f\u4f60\u7528\u4e8e\u5728\u5b89\u5353\u8bbe\u5907\u4e0a\u5b89\u88c5\u5e94\u7528\u7a0b\u5e8f\u7684APK\u6587\u4ef6\u3002\u5c06\u5176\u4f20\u8f93\u5230\u5b89\u5353\u8bbe\u5907\u5e76\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n

\u603b\u4e4b\uff0c\u5728Python\u4e2d\u5f00\u53d1\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\u662f\u5b8c\u5168\u53ef\u80fd\u7684<\/p>\n

<\/figure>\n<\/p>\n

\u3002\u867d\u7136\u5b83\u53ef\u80fd\u65e0\u6cd5\u63d0\u4f9b\u50cfJava\u548cKotlin\u90a3\u6837\u4e30\u5bcc\u7684\u539f\u751fAndroid\u652f\u6301\uff0c\u4f46\u5bf9\u4e8ePython\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u5b83\u662f\u4e00\u4e2a\u975e\u5e38\u65b9\u4fbf\u7684\u65b9\u5f0f\u3002\u901a\u8fc7Kivy\u548cBuildozer\u642d\u5efa\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3a\u8de8\u5e73\u53f0\u7684\u5b89\u5353\u5e94\u7528\u3002\u795d\u4f60\u5f00\u53d1\u6109\u5feb\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5982\u4f55\u4f7f\u7528Python\u5f00\u53d1\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\uff08app\uff09Python\u662f\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u56e0\u5176\u7b80\u6d01\u7684\u8bed\u6cd5\u89c4\u5219\u548c\u5f3a\u5927\u7684\u5e93\u652f\u6301\u5e7f\u53d7\u7a0b\u5e8f\u5458\u559c\u7231\u3002\u7136\u800cPython\u5728\u5b89\u5353\u5e94\u7528\u5f00\u53d1\u65b9\u9762\u7684\u5e94\u7528\u5e76\u4e0d\u50cfJava\u6216Kot<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[543,16488,23486,14,171],"class_list":["post-17089","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-543","tag-app","tag-app--","tag-14","tag-171"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/17089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=17089"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/17089\/revisions"}],"predecessor-version":[{"id":17146,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/17089\/revisions\/17146"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=17089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=17089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=17089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}