{"id":70,"date":"2019-01-24T00:15:02","date_gmt":"2019-01-23T16:15:02","guid":{"rendered":"http:\/\/140.130.32.81\/wp\/?p=70"},"modified":"2022-04-17T14:20:25","modified_gmt":"2022-04-17T06:20:25","slug":"pyqt5-%e5%ae%89%e8%a3%9d%e6%95%99%e5%ad%b8-hello-world","status":"publish","type":"post","link":"https:\/\/no-rule.tw\/?p=70","title":{"rendered":"[PyQt5] \u5b89\u88dd\u6559\u5b78&amp;\u7b2c\u4e00\u652fUI\u7a0b\u5f0f &#8212; Hello World"},"content":{"rendered":"<p><a href=\"https:\/\/zh.wikipedia.org\/zh-tw\/PyQt\">PyQt<\/a>\u662f\u4e00\u5957\u529f\u80fd\u6bd4\u8f03\u5b8c\u6574\u7684UI\u8a2d\u8a08\u5957\u4ef6\uff0c\u5728\u9019\u500b<del>\u6c92\u6709\u7f8e\u9e97\u7684\u4ecb\u9762\u5c31\u6c92\u6709\u4f7f\u7528\u8005(\u8aa4)\u7684\u5e74\u4ee3<\/del>\uff0c\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u4e4b\u4e00\u963f!!!<br \/>\nPyQt\u662f\u6bd4Python\u5167\u5efa\u7684<a href=\"https:\/\/wiki.python.org\/moin\/TkInter\">Tkinter<\/a>\u9084\u8981\u5bb9\u6613\u8a2d\u8a08\u7684\u529f\u5177\uff0c\u56e0\u70ba\u4ed6\u6709\u975e\u5b98\u65b9\u7684\u4ecb\u9762\u8a2d\u8a08\u7a0b\u5f0fQt Designer\uff0c\u8b93\u6211\u5011\u53ef\u4ee5\u66f4\u52a0\u5bb9\u6613\u7684\u628aUI\u8a2d\u8a08\u51fa\u4f86\uff0c\u5c31\u597d\u50cf\u5728\u4f7f\u7528Microsoft \u7684studio\u4e00\u6a23\uff0c\u5c31\u8b93\u6211\u5011\u4e00\u8d77\u4f86Hello World\u4e00\u4e0b\u5427!<br \/>\n<!--more--><\/p>\n<h1>I.\u5b89\u88dd<\/h1>\n<p>\u9996\u5148\uff0c\u6253\u958b \u547d\u4ee4\u63d0\u793a\u5b57\u5143 \u5229\u7528 pip \u6307\u4ee4\u4f86\u5b89\u88dd pyqt5 \u548c\u4ed6\u7684\u5de5\u5177\u3002<span style=\"color: #ff0000;\">(\u8a18\u5f97\u4f7f\u7528\u7ba1\u7406\u54e1\u6b0a\u9650\u57f7\u884c)<\/span><\/p>\n<blockquote>\n<pre class=\"font-size:13 line-height:20 toolbar:1 toolbar-delay:false popup:false lang:sh decode:true \">pip install pyqt5\npip install pyqt5-tools<\/pre>\n<\/blockquote>\n<p>pyqt5-tools \u662f\u4e00\u500b\u975e\u5b98\u65b9\u7684\u5957\u4ef6\uff0c\u900f\u904e\u9019\u500btools \u6211\u5011\u624d\u80fd\u4f7f\u7528Qt Designer\u3002<br \/>\n<img loading=\"lazy\" title=\"CMD\u6307\u4ee4\u7d50\u679c\u5716\" src=\"https:\/\/i0.wp.com\/nr.img.no-rule.tw\/imgs\/p70\/P3yq8YH.png?resize=677%2C442&#038;ssl=1\" alt=\"\" width=\"677\" height=\"442\" data-recalc-dims=\"1\" \/><\/p>\n<h1>II.QtDesigner \u8aaa\u51faHello World<\/h1>\n<p>1.\u9ede\u64ca \u958b\u59cb \uff0c\u8f38\u5165 desinger \uff0c\u5c31\u53ef\u4ee5\u770b\u898bdesigner\u6307\u4ee4\u3002<br \/>\n<img loading=\"lazy\" class=\"alignnone\" title=\"\" src=\"https:\/\/i0.wp.com\/nr.img.no-rule.tw\/imgs\/p70\/ch0geWb.png?resize=300%2C374&#038;ssl=1\" alt=\"\" width=\"300\" height=\"374\" data-recalc-dims=\"1\" \/><\/p>\n<p>2.\u958b\u555f\u5f8c\u7684\u756b\u9762\u5982\u4e0b\uff0c\u6211\u5011\u9078\u64c7 Widget \u4f86\u8a66\u8a66\u770b\u5427!<br \/>\n<img loading=\"lazy\" title=\"\" src=\"https:\/\/i0.wp.com\/nr.img.no-rule.tw\/imgs\/p70\/NxdG5LG.png?resize=900%2C485&#038;ssl=1\" alt=\"\" width=\"900\" height=\"485\" data-recalc-dims=\"1\" \/><\/p>\n<p>3. \u9019\u500b\u4ecb\u9762\u662f\u4e0d\u662f\u5f88\u50cfStudio\u5462??<br \/>\n\u6211\u5011\u5c31\u62c9\u4e00\u500b QLable\u3001\u4e00\u500bQPlshButton \uff0c\u64fa\u653e\u4e00\u4e0b\u4f4d\u7f6e(\u660e\u660e\u5c31\u5f88\u96a8\u4fbf)\uff0c<br \/>\n\u6211\u5011\u7684\u52d5\u4f5c\u5c31\u662f\u6309\u4e0b\u6309\u9215\uff0c\u7136\u5f8c\u8df3\u51faHello World \u7684\u5b57\u3002<br \/>\n\u597d\u4e86\u4e4b\u5f8c\u5c31\u5132\u5b58\u6a94\u6848\u5427!\u00a0 \u9019\u908a\u6211\u5c31\u5b58\u6210 UI.ui \u3002<br \/>\n<span style=\"color: #ff6600; background-color: #ffff99;\">Tip.. \u4f7f\u7528\u5feb\u6377\u9375 Ctrl+R \u53ef\u4ee5\u9810\u89bd\u8996\u7a97\u5594!<\/span><br \/>\n<img loading=\"lazy\" title=\"\" src=\"https:\/\/i0.wp.com\/nr.img.no-rule.tw\/imgs\/p70\/EKnd4WW.png?resize=825%2C445&#038;ssl=1\" alt=\"\" width=\"825\" height=\"445\" data-recalc-dims=\"1\" \/><\/p>\n<p>4.\u6211\u5011\u6309\u4f4f Shift \u5728\u6309\u6ed1\u9f20\u53f3\u9375\uff0c\u57f7\u884c\u5728\u6b64\u8655\u958b\u555f\u547d\u4ee4\u8996\u7a97(win10\u7684\u8a71\u5247\u662f PowerShell)\uff0c\u900f\u904e\u4e0b\u5217\u6307\u4ee4\u5c07 ui \u6a94\u8f49\u6210 py \u6a94\u3002<\/p>\n<blockquote>\n<pre class=\"font-size:13 line-height:20 toolbar:1 lang:sh decode:true \">pyuic5 UI.ui &gt; UI.py<\/pre>\n<\/blockquote>\n<p><img loading=\"lazy\" title=\"\" src=\"https:\/\/i0.wp.com\/nr.img.no-rule.tw\/imgs\/p70\/ycop8WD.png?resize=825%2C533&#038;ssl=1\" alt=\"\" width=\"825\" height=\"533\" data-recalc-dims=\"1\" \/><\/p>\n<p>5.\u8f49\u63db\u5b8c\uff0c\u6211\u5011\u5c31\u591a\u4e86\u4e00\u500b UI.py \u7684\u6a94\u6848\u4e86! (app.py\u6a94\u6848\u662f\u6211\u53e6\u5916\u65b0\u589e\u7684\uff0c\u53c3\u8003\u6b65\u9a5f 6)<br \/>\n<img loading=\"lazy\" title=\"\" src=\"https:\/\/i0.wp.com\/nr.img.no-rule.tw\/imgs\/p70\/IFwwQiI.png?resize=825%2C533&#038;ssl=1\" alt=\"\" width=\"825\" height=\"533\" data-recalc-dims=\"1\" \/><\/p>\n<p>6.\u63a5\u8457\u6211\u5011\u518d\u65b0\u589e\u4e00\u500b app.py \u7684\u6a94\u6848\uff0c\u5167\u5bb9\u5982\u4e0b\uff1a<\/p>\n<blockquote>\n<pre class=\"font-size:13 line-height:20 toolbar:1 lang:python decode:true\">import sys\nfrom PyQt5.QtWidgets import QDialog, QApplication\nfrom UI import Ui_Form\nclass AppWindow(QDialog):\n def __init__(self):\n super().__init__()\n self.ui = Ui_Form()\n self.ui.setupUi(self)\n #\u7d81\u4e0a\u8207\u9ede\u64ca\u4e8b\u4ef6\u5c0d\u61c9\u7684function\uff0c\u6240\u6709\u6771\u897f\u90fd\u5728ui\u5e95\u4e0b\uff01\uff01\n self.ui.pushButton.clicked.connect(self.pushButton_Click)\n self.show()\n def pushButton_Click(self):\n self.ui.label.setText(\"Hello World\")\napp = QApplication(sys.argv)\nw = AppWindow()\nw.show()\nsys.exit(app.exec_())<\/pre>\n<\/blockquote>\n<p>7.\u4f7f\u7528Python \u57f7\u884c app.py \u5c31\u53ef\u4ee5\u8b93\u5b83\u8aaa\u51fa Hello\u4e86\u5594!<br \/>\n<img loading=\"lazy\" title=\"\" src=\"https:\/\/i0.wp.com\/i.imgur.com\/c840D8x.png?resize=416%2C338&#038;ssl=1\" alt=\"\" width=\"416\" height=\"338\" data-recalc-dims=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PyQt\u662f\u4e00\u5957\u529f\u80fd\u6bd4\u8f03\u5b8c\u6574\u7684UI\u8a2d\u8a08\u5957\u4ef6\uff0c\u5728\u9019\u500b\u6c92\u6709\u7f8e\u9e97\u7684\u4ecb\u9762\u5c31\u6c92\u6709\u4f7f\u7528\u8005(\u8aa4)\u7684\u5e74\u4ee3\uff0c\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u4e4b\u4e00\u963f&#8230; &raquo; <a class=\"read-more-link\" href=\"https:\/\/no-rule.tw\/?p=70\">\u95b1\u8b80\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[34,36],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/no-rule.tw\/index.php?rest_route=\/wp\/v2\/posts\/70"}],"collection":[{"href":"https:\/\/no-rule.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/no-rule.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/no-rule.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/no-rule.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":2,"href":"https:\/\/no-rule.tw\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":264,"href":"https:\/\/no-rule.tw\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions\/264"}],"wp:attachment":[{"href":"https:\/\/no-rule.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/no-rule.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/no-rule.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}