{"id":21135,"date":"2024-01-12T11:06:18","date_gmt":"2024-01-12T03:06:18","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=21135"},"modified":"2024-01-12T11:06:18","modified_gmt":"2024-01-12T03:06:18","slug":"pyqt5%e5%bc%80%e5%8f%91%e5%ae%89%e5%8d%93app%e6%93%8d%e4%bd%9c%e5%8a%9e%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2024\/21135\/","title":{"rendered":"pyqt5\u5f00\u53d1\u5b89\u5353app\u64cd\u4f5c\u529e\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"<p>PyQt5\u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684Python GUI\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5f00\u53d1\u591a\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002\u540c\u65f6\uff0c\u901a\u8fc7QPython\u548cPyQt5\u7684\u7ed3\u5408\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3aAndroid\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6b65\u9aa4\uff0c\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyQt5\u5f00\u53d1\u5b89\u5353\u5e94\u7528\uff1a<\/p>\n<p>1. \u5b89\u88c5PyQt5<\/p>\n<p>\u5b89\u88c5PyQt5\u4e4b\u524d\u9700\u8981\u5b89\u88c5Python\u73af\u5883\uff0c\u63a8\u8350\u4f7f\u7528Python3\u3002\u901a\u8fc7pip\u547d\u4ee4\u5373\u53ef\u5b89\u88c5PyQt5\uff1a`pip install PyQt5`<\/p>\n<p>2. \u5b89\u88c5 QPython<\/p>\n<p>QPython\u662f\u4e00\u4e2a\u8fd0\u884cPython\u7684\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\uff0c\u63d0\u4f9b\u4e86Python\u89e3\u91ca\u5668\u3001\u6807\u51c6\u5e93\u3001\u7f16\u8f91\u5668\u7b49\u529f\u80fd\u3002\u53ef\u4ee5\u5728Play Store\u4e2d\u641c\u7d22QPython\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p>3. \u5f00\u53d1\u5e94\u7528<\/p>\n<p>\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5728QPython\u7684\u7f16\u8f91\u5668\u4e2d\u7f16\u5199\u4ee3\u7801\uff0c\u4f7f\u7528PyQt5\u7684\u8bed\u6cd5\u8fdb\u884c\u5f00\u53d1\u3002\u5bf9\u4e8e\u5e38\u89c1\u7684UI\u63a7\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7Qt<a href=\"https:\/\/www.anzhuoe.com\/\">\u5b89\u5353app\u5236\u4f5c<\/a> Designer\u8fdb\u884c\u53ef\u89c6\u5316\u5f00\u53d1\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528PyQt5\u7684\u4f8b\u5b50\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>import sys<\/p>\n<p>from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton<\/p>\n<p>class Example(QWidget):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.initUI()<\/p>\n<p>    def initUI(self):<\/p>\n<p>        self.lbl = QLabel(&#8220;Hello World!&#8221;, self)<\/p>\n<p>        self.lbl.move(50, 50)<\/p>\n<p>        btn = QPushButton(&#8220;Quit&#8221;, self)<\/p>\n<p>        btn.clicked.connect(self.close)<\/p>\n<p>        btn.move(50, 100)<\/p>\n<p>        self.setGeometry(300, 300, 250, 150)<\/p>\n<p>        self.setWindowTitle(&#8216;Hello World&#8217;)<\/p>\n<p><a href=\"https:\/\/www.anzhuoe.com\/\">\u5b89\u5353app<\/a><\/p>\n<p>        self.show()<\/p>\n<p>if __name__ == &#8216;__main<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-04\/07\/09\/34208099550.jpg\" \/><\/figure>\n<\/p>\n<p>__&#8217;:<\/p>\n<p>    app = QApplication(sys.argv)<\/p>\n<p>    ex = Example()<\/p>\n<p>    sys.exit(app.exec_())<\/p>\n<p>&#8220;`<\/p>\n<p>\u901a\u8fc7QPython\u8fd0\u884c\u4ee5\u4e0a\u4ee3\u7801\uff0c\u53ef\u4ee5\u5728\u5b89\u5353\u8bbe\u5907\u4e0a\u770b\u5230\u4e00\u4e2a\u663e\u793a\u201cHello World\u201d\u6807\u7b7e\u548c\u4e00\u4e2a\u201cQuit\u201d\u6309\u94ae\u7684\u754c\u9762\u3002<\/p>\n<p>4. \u6253\u5305\u5e94\u7528<\/p>\n<p>\u5728\u5f00\u53d1\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5c06\u4ee3\u7801\u6253\u5305\u6210\u5b89\u5353\u5e94\u7528\u3002\u53ef\u4ee5\u901a\u8fc7Buildozer\u5de5\u5177\u8fdb\u884c\u6253\u5305\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>&#8211; \u5b89\u88c5Buildozer\uff1a`pip install buildozer`<\/p>\n<p>&#8211; \u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff1a`buildozer init`<\/p>\n<p>&#8211; \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u5e94\u7528\u540d\u79f0\u548c\u7248\u672c\u53f7\u7b49\u4fe1\u606f<\/p>\n<p>&#8211; \u6267\u884c\u547d\u4ee4\u8fdb\u884c\u6784\u5efa\uff1a`buildozer android debug deploy run`\uff0c\u6784\u5efa\u7684\u8fc7\u7a0b\u4e2d\u4f1a\u8fdb\u884c\u4ee3\u7801\u7f16\u8bd1\u548c\u6784\u5efaAndroid APK\u5305<\/p>\n<p>&#8211; \u5f53\u6784\u5efa\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728\u8bbe\u5907\u4e0a\u5b89\u88c5\u5e76\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u7efc\u4e0a\uff0cPyQt5\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684GUI\u5f00\u53d1\u529f\u80fd\uff0c\u7ed3\u5408QPython\u548cBuildozer\u53ef\u4ee5\u5feb\u901f\u7684\u5f00\u53d1\u5e76\u6253\u5305\u51fa\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\uff0c\u5177\u6709\u8f83\u597d\u7684\u5f00\u53d1\u6548\u7387\u548c\u4f7f\u7528\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PyQt5\u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684Python GUI\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5f00\u53d1\u591a\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002\u540c\u65f6\uff0c\u901a\u8fc7QPython\u548cPyQt5\u7684\u7ed3\u5408\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3aAndroid\u5e94\u7528\u7a0b\u5e8f<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,25844,14,25845,72],"class_list":{"0":"post-21135","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-zuoapp","7":"tag-81","8":"tag-app","9":"tag-14","11":"tag-72"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/21135","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\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=21135"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/21135\/revisions"}],"predecessor-version":[{"id":21151,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/21135\/revisions\/21151"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=21135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=21135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=21135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}