{"id":806,"date":"2023-07-26T14:52:57","date_gmt":"2023-07-26T06:52:57","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=806"},"modified":"2023-07-26T14:52:57","modified_gmt":"2023-07-26T06:52:57","slug":"app%e5%bc%80%e5%8f%91python%e5%8f%af%e4%bb%a5%e5%98%9b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/806\/","title":{"rendered":"app\u5f00\u53d1python\u53ef\u4ee5\u561b\uff1f"},"content":{"rendered":"

Title: \u521d\u5b66\u8005\u6307\u5357\uff1a\u4f7f\u7528Python\u8fdb\u884cAPP\u5f00\u53d1<\/p>\n

\u5728\u5f53\u524d\u7684\u6280\u672f\u65f6\u4ee3\uff0c\u667a\u80fd\u624b\u673a\u5e94\u7528\u7a0b\u5e8f(APP)\u7684\u5e7f\u6cdb\u4f7f\u7528\u4f7f\u5f97\u624b\u673a\u6210\u4e3a\u4fe1\u606f\u65f6\u4ee3\u7684\u5fc5\u5907\u5de5\u5177\u3002\u800c\u4f5c\u4e3a\u4e00\u95e8\u6613\u5b66\u3001\u6613\u7528\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0cPython\u5df2\u6210\u4e3a\u4f17\u591a\u521d\u5b66\u8005\u53ca\u4e13\u5bb6\u7684\u9996\u9009\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528Python\u8fdb\u884cAPP\u5f00\u53d1\u7684\u539f\u7406\u548c\u57fa\u672c\u6b65\u9aa4\uff0c\u9002\u5408\u521d\u5b66\u8005\u53c2\u8003\u3002<\/p>\n

\u4e00\u3001Python\u5728APP\u5f00\u53d1\u4e2d\u7684\u4f18\u52bf<\/p>\n

1. \u4ee3\u7801\u7b80\u6d01\u3001\u53ef\u8bfb\u6027\u5f3a\uff1aPython\u7684\u8bed\u6cd5\u7b80\u6d01\u3001\u4f18\u7f8e\uff0c\u5e76\u4e14\u62e5\u6709\u4e30\u5bcc\u7684\u5e93\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u4ee3\u7801\u7f16\u5199\u548c\u8c03\u8bd5\u3002<\/p>\n

2. \u6570\u636e\u5904\u7406\u80fd\u529b\u5f3a\uff1aPython\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65b9\u9762\u5177\u6709\u8f83\u9ad8\u6027\u80fd\uff0c\u8fd9\u4f7f\u5f97\u5b83\u5728\u5927\u6570\u636e\u3001\u4eba\u5de5\u667a\u80fd\u7b49\u9886\u57df\u5177\u6709\u4f18\u52bf\u3002<\/p>\n

3. \u793e\u533a\u5e9e\u5927\uff1aPython\u7684\u7528\u6237\u7fa4\u4f53\u5e9e\u5927\uff0c\u8fd9\u610f\u5473\u7740\u6709\u4e30\u5bcc\u7684\u5b66\u4e60\u8d44\u6e90\u3001\u6280\u672f\u95ee\u7b54\u53ca\u7ecf\u9a8c\u5206\u4eab\u3002<\/p>\n

4. \u8de8\u5e73\u53f0\u5f00\u53d1\u80fd\u529b\uff1a\u4f7f\u7528Python\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5f00\u53d1\u51fa\u5728Android\u3001iOS\u7b49\u591a\u4e2a\u5e73\u53f0\u8fd0\u884c\u7684\u5e94\u7528\u3002<\/p>\n

\u4e8c\u3001Python APP\u5f00\u53d1\u7684\u57fa\u672c\u539f\u7406<\/p>\n

\u4f7f\u7528Python\u8fdb\u884cAPP\u5f00\u53d1\u7684\u5173\u952e\u5728\u4e8e\u9009\u62e9\u5408\u9002\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u8fd9\u4e9b\u5e93\u80fd\u591f\u4e3aPython\u63d0\u4f9b\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762(GUI)\u3001\u8bbf\u95ee\u8bbe\u5907\u786c\u4ef6\u5982\u6444\u50cf\u5934\u3001\u4f20\u611f\u5668\u7b49\uff0c\u4ece\u800c\u4f7fPython\u5177\u6709\u5f00\u53d1APP\u7684\u80fd\u529b\u3002<\/p>\n

1. Kivy: Kivy\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u684c\u9762\u548c\u79fb\u52a8\u5e94\u7528\u7684\u5f00\u6e90Python\u5e93\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528Python\u7f16\u5199\u539f\u751f\u5e94\u7528\uff0c\u540c\u65f6\u5177\u5907\u8de8\u5e73\u53f0\u8fd0\u884c\u7684\u80fd\u529b\u3002<\/p>\n

2. BeeWare: BeeWare\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u539f\u751f\u8f6f\u4ef6\u7684Python\u5e93\u548c\u5de5\u5177\u96c6\uff0c\u53ef\u4ee5\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u5728\u591a\u4e2a\u5e73\u53f0\u4e0a\u521b\u5efa\u539f\u751f GUI \u5e94\u7528\u7684\u80fd\u529b\u3002<\/p>\n

3. Pyqt5\u548cPyqt6: Pyqt\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u684c\u9762\u7a0b\u5e8f\u7684Python\u5e93\uff0c\u652f\u6301\u8de8\u5e73\u53f0\u5f00\u53d1\u3002<\/p>\n

\u6b64\u5916\uff0c\u50cfFlask\u3001Django\u8fd9\u6837\u7684Python Web\u6846\u67b6\u4e5f\u53ef\u4ee5\u7528\u6765\u521b\u5efaWeb APP\u3002<\/p>\n

\u4e09\u3001\u4f7f\u7528Python\u8fdb\u884cAPP\u5f00\u53d1\u7684\u57fa\u672c\u6b65\u9aa4<\/p>\n

\u6b65\u9aa4\u4e00\uff1aAPP\u5f00\u53d1<\/a>\u5b89\u88c5Python\u73af\u5883<\/p>\n

\u5728\u8fdb\u884cAPP\u5f00\u53d1\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u5b89\u88c5Python\u73af\u5883\u3002\u53ef\u4ee5\u5728Python\u5b98\u7f51(https:\/\/www.python.org\/downloads\/)\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684Python\u5e76\u5b89\u88c5\u3002<\/p>\n

\u6b65\u9aa4\u4e8c\uff1a\u9009\u62e9\u5f00\u53d1\u5de5\u5177<\/p>\n

\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883(IDE),\u4f8b\u5982Visual Studio Code\u3001PyCharm\u7b49\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7f16\u5199\u4ee3\u7801\u7684\u6548\u7387\uff0c\u540c\u65f6\u4fbf\u4e8e\u4ee3\u7801\u8c03\u8bd5\u3002<\/p>\n

\u6b65\u9aa4\u4e09\uff1a\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93<\/p>\n

\u5728Python\u73af\u5883\u548c\u5f00\u53d1\u5de5\u5177\u51c6\u5907\u597d\u540e\uff0c\u9700\u8981\u5b89\u88c5\u76f8\u5e94\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u4f8b\u5982\uff0c\u5b89\u88c5Kiv<\/p>\n

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

y\uff0c\u53ef\u4ee5\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pip install kivy<\/p>\n

“`<\/p>\n

\u6b65\u9aa4\u56db\uff1a\u7f16\u5199APP\u4ee3\u7801<\/p>\n

\u4f7f\u7528\u9009\u5b9a\u7684IDE\u7f16\u5199\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f7f\u7528Kivy\u5f00\u53d1\u7684\u8ba1\u7b97\u5668\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n

“`python<\/p>\n

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

from kivy.uix.button import Button<\/p>\n

from kivy.uix.textinput import TextInput<\/p>\n

from kivy.uix.boxlayout import BoxLayout<\/p>\n

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

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

layout = BoxLayout(orientation=’vertical’)<\/p>\n

self.result = TextInput(font_size=40, size_hint_y=0.3, readonly=True, multiline=False)<\/p>\n

layout.add_widget(self.result)<\/p>\n

buttons = [‘7’, ‘8’, ‘9’, ‘\/’, ‘4’, ‘5’, ‘6’, ‘*’, ‘1’, ‘2’, ‘3’, ‘-‘, ‘0’, ‘.’, ‘=’, ‘+’] <\/p>\n

for i in range(5):<\/p>\n

h_layout = BoxLayout(spacing=10)<\/p>\n

for j in range(4):<\/p>\n

button = Button(text=buttons[i*4+j], pos_hint={‘center_x’: .5, ‘center_y’: .5}, font_size=40)<\/p>\n

button.bind(on_press=self.on_button_press)<\/p>\n

h_layout.add_widget(button)<\/p>\n

layout.add_widget(h_layout)<\/p>\n

return layout<\/p>\n

def on_button_press(self, instance):<\/p>\n

current = self.result.text<\/p>\n

new_text = instance.text<\/p>\n

if new_text == ‘=’:<\/p>\n

try:<\/p>\n

APP<\/a> self.result.text = str(eval(current))<\/p>\n

except Exception as e:<\/p>\n

self.result.text = “Error”<\/p>\n

else:<\/p>\n

self.result.text = current + new_text<\/p>\n

if __name__ == ‘__main__’:<\/p>\n

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

“`<\/p>\n

\u6b65\u9aa4\u4e94\uff1a\u5728\u6a21\u62df\u5668\u6216\u8005\u5b9e\u9645\u8bbe\u5907\u4e0a\u8fd0\u884cAPP<\/p>\n

\u7ecf\u8fc7\u8c03\u8bd5\u548c\u4f18\u5316\u540e\uff0c\u53ef\u4ee5\u5c06APP\u90e8\u7f72\u5230\u6a21\u62df\u5668\u6216\u8005\u5b9e\u9645\u8bbe\u5907\u4e0a\u8fdb\u884c\u8fd0\u884c\u548c\u6d4b\u8bd5\u3002<\/p>\n

\u901a\u8fc7\u4e0a\u8ff0\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u521d\u5b66\u8005\u5bf9Python\u8fdb\u884cAPP\u5f00\u53d1\u6709\u4e86\u66f4\u660e\u786e\u7684\u4e86\u89e3\u3002\u4e0d\u8fc7\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9664\u975e\u7279\u5b9a\u9700\u6c42\uff0c\u5426\u5219\u4f7f\u7528Python\u8fdb\u884cAPP\u5f00\u53d1\u53ef\u80fd\u4e0d\u662f\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u3002Android\u3001iOS\u539f\u751f\u5f00\u53d1\u6216\u8005\u4f7f\u7528\u5176\u4ed6APP\u5f00\u53d1\u6846\u67b6\uff0c\u5982React Native\u548cFlutter\uff0c\u53ef\u80fd\u5177\u6709\u66f4\u9ad8\u7684\u6548\u7387\u548c\u6027\u80fd\u3002\u4e0d\u8fc7\uff0c\u4e86\u89e3\u548c\u5c1d\u8bd5\u4f7f\u7528Python\u5f00\u53d1APP\u4ecd\u5177\u6709\u4e00\u5b9a\u5b66\u4e60\u4ef7\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Title: \u521d\u5b66\u8005\u6307\u5357\uff1a\u4f7f\u7528Python\u8fdb\u884cAPP\u5f00\u53d1\u5728\u5f53\u524d\u7684\u6280\u672f\u65f6\u4ee3\uff0c\u667a\u80fd\u624b\u673a\u5e94\u7528\u7a0b\u5e8f(APP)\u7684\u5e7f\u6cdb\u4f7f\u7528\u4f7f\u5f97\u624b\u673a\u6210\u4e3a\u4fe1\u606f\u65f6\u4ee3\u7684\u5fc5\u5907\u5de5\u5177\u3002\u800c\u4f5c\u4e3a\u4e00\u95e8\u6613\u5b66\u3001\u6613\u7528\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0cPython\u5df2<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1890,1888,1889,25,797],"topic":[],"class_list":["post-806","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-app-","tag-1888","tag-exe","tag-25","tag-797"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=806"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/806\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=806"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}