{"id":608,"date":"2020-01-09T00:36:34","date_gmt":"2020-01-08T16:36:34","guid":{"rendered":"http:\/\/www.mustenaka.cn\/?p=608"},"modified":"2020-01-09T00:36:34","modified_gmt":"2020-01-08T16:36:34","slug":"pyqtbegin1","status":"publish","type":"post","link":"https:\/\/www.mustenaka.cn\/index.php\/2020\/01\/09\/pyqtbegin1\/","title":{"rendered":"PyQt\u5165\u95e81-Python\u7684\u684c\u9762\u7a0b\u5e8f\uff0cHelloWorld"},"content":{"rendered":"<p>\u6700\u8fd1\u5f00\u59cb\u4e0a\u624bPythonQt\u9879\u76ee\u7684\u5b66\u4e60\uff0c\u5495\u8bb0\u672c\u7b14\u8bb0<\/p>\n<p>\u9996\u5148\u662fPyQt\u7684\u5b89\u88c5\uff0c\u76f4\u63a5pip\u8d70\u8d77<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">pip install pyqt5\r\npip install pyqt5-tools<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u60f3\u76f4\u63a5\u4ee3\u7801\u5199\u754c\u9762\uff0c\u76f4\u63a5\u7b2c\u4e00\u884c\u5c31\u53ef\u4ee5\u4e86\uff08\u7c7b\u4f3c\u4e8eJAVA\u76f4\u63a5\u88f8\u5199Jpanel\uff09\uff0c\u8fd9\u6837\u7684\u6548\u7387\u6781\u4f4e\uff0c\u66f4\u52a0\u63a8\u8350\u7684\u662f\u4f7f\u7528\u56fe\u5f62\u5316\u7684\u8bbe\u8ba1\u65b9\u5f0f\uff0c\u56e0\u6b64\u9700\u8981\u5b89\u88c5\u4e0b\u9762\u7684\u5185\u5bb9\uff0c\u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u76f4\u63a5\u641c\u7d22\u680f\u641c\u7d22\u5e76\u6253\u5f00\uff1aDesginer<\/p>\n<p>\u5982\u679c\u627e\u4e0d\u5230\u53ef\u4ee5Python\u7684\u5b89\u88c5\u76ee\u5f55\u4e2d\u7684 \\Library\\bin \u627e\u5230\u6267\u884c\u6587\u4ef6<\/p>\n<div id=\"attachment_609\" style=\"width: 705px\" class=\"wp-caption alignnone\"><img fetchpriority=\"high\" decoding=\"async\" aria-describedby=\"caption-attachment-609\" src=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/designerrrrr-300x149.png\" alt=\"\" width=\"695\" height=\"345\" class=\" wp-image-609\" srcset=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/designerrrrr-300x149.png 300w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/designerrrrr-768x382.png 768w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/designerrrrr.png 779w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><p id=\"caption-attachment-609\" class=\"wp-caption-text\">\u641c\u7d22\u680f\u6253\u5f00\u5373\u53ef\uff0c\u5982\u679c\u9700\u8981\u53ef\u4ee5\u81ea\u884c\u521b\u5efa\u684c\u9762\u5feb\u6377\u65b9\u5f0f<\/p><\/div>\n<p>\u6253\u5f00\u5b8c\u6210\u4e4b\u540e\u4f1a\u770b\u5230\u8fd9\u4e2a\u9875\u9762(\u4e00\u4e2a\u5f88\u7ecf\u5178\u7684\u754c\u9762\u8bbe\u8ba1\u9875\u9762)\uff0c\u6211\u4eec\u4e00\u822c\u800c\u8a00\u4e0d\u521b\u5efaweb\u7aef\u7684\u8bdd\u76f4\u63a5\u9009\u62e9Main Window\u6216\u8005Wieget\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/8MYQ235W2MUGPCLDFPXQ-300x163.png\" alt=\"\" width=\"736\" height=\"400\" class=\"alignnone  wp-image-610\" srcset=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/8MYQ235W2MUGPCLDFPXQ-300x163.png 300w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/8MYQ235W2MUGPCLDFPXQ-768x417.png 768w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/8MYQ235W2MUGPCLDFPXQ-1024x557.png 1024w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/8MYQ235W2MUGPCLDFPXQ.png 1928w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/p>\n<p>\u4ee5\u9009\u62e9Main Windows\u3010\u4e3b\u7a97\u4f53\u3011\u4e3a\u4f8b\uff0c\u76f4\u63a5\u521b\u5efa\u4e4b\u540e\u4f1a\u770b\u5230\u4e00\u4e2a\u7c7b\u4f3c\u4e8e\u7a7a\u767d\u7a0b\u5e8f\u7684\u9875\u9762\uff0c\u8fd9\u5c31\u4e5f\u662f\u6211\u4eec\u7684\u8bbe\u8ba1\u9875\u9762\u4e86\uff0c\u5de6\u8fb9\u662f\u6211\u4eec\u7684\u63a7\u4ef6\u680f\uff0c\u53f3\u8fb9\u5219\u662f\u6211\u4eec\u7684\u72b6\u6001\u680f\uff0c\u5176\u4e2d\u6700\u4e0a\u9762\u7684\u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u8d44\u6e90\u7ba1\u7406\u5668\uff0c\u5b83\u80fd\u591f\u6709\u6548\u7684\u5173\u7cfb\u5404\u4e2a\u7ec4\u4ef6\u4ee5\u53ca\u5404\u4e2a\u753b\u9762\u4e4b\u95f4\u7684\u5c42\u7ea7\u5173\u7cfb\uff08\u6bd4\u5982\u7236\u7ea7\u5b50\u7ea7\u5173\u7cfb\uff09\uff0c\u4e2d\u95f4\u7684\u754c\u9762\u5c31\u662f\u63a7\u4ef6\uff0c\u6216\u8005\u7a97\u4f53\u672c\u8eab\u7684\u5c5e\u6027\u754c\u9762\uff0c\u5728\u8fd9\u4e2a\u754c\u9762\u4e4b\u4e2d\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u5404\u79cd\u57fa\u672c\u7684\u5c5e\u6027\uff08\u5982\u5b57\u4f53\u7b49\uff09<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u8bd5\u7740\u5199\u4e00\u4e2aUI\u8bbe\u8ba1\u4e2d\u7684Hello World\uff0c\u62d6\u52a8\u65c1\u8fb9\u7684Label\u6807\u7b7e\u5230\u4e2d\u592e\uff0c\u53cc\u51fb\u4fee\u6539\u6587\u5b57\u5185\u5bb9\uff0c\u5199\u4e0a\u201cHello World &#8212; \u4f60\u597d\uff0c\u4e16\u754c\u201d\uff0c\u4e4b\u540e\u5728\u5c5e\u6027\u6846\u4e2d\u9009\u62e9Font\u3010\u5b57\u4f53\u3011\uff0c\u5e76\u6253\u5f00\u5b57\u4f53\u76f8\u5173\u9009\u62e9\u754c\u9762\uff0c\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u5b57\u4f53\u548c\u5408\u9002\u7684\u5b57\u53f7\u5927\u5c0f\uff0c\u662f\u5426\u52a0\u7c97\u7b49\u7b49\u5e38\u89c4\u9009\u62e9\u3002\uff08\u6ce8\u610f\uff0c\u6b64\u65f6\u7684\u5b57\u4f53\u9009\u62e9\u548cWindows\u81ea\u5e26\u5b57\u4f53\u6709\u5173\uff0c\u540c\u65f6\u4e2d\u6587\u7684\u652f\u6301\u4e5f\u548c\u7cfb\u7edf\u7684\u652f\u6301\u6709\u5173\uff0c\u6ce8\u610f\u7684\u670b\u53cb\u4f1a\u53d1\u73b0\uff0c\u65b0\u7248\u672c\u4f1a\u8fdb\u884clocal\u5730\u70b9\u89c4\u7c7b\uff0c\u4f1a\u9ed8\u8ba4\u628a\u6211\u4eec\u5bfc\u5230China\u4e2d\uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/U1MN3OW6905@559A-300x163.png\" alt=\"\" width=\"751\" height=\"408\" class=\"alignnone  wp-image-611\" srcset=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/U1MN3OW6905@559A-300x163.png 300w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/U1MN3OW6905@559A-768x417.png 768w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/U1MN3OW6905@559A-1024x557.png 1024w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/U1MN3OW6905@559A.png 1928w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/p>\n<p>\u5728\u5b8c\u6210\u57fa\u672c\u7684Hello World\u4e4b\u540e\uff0c\u5982\u4f55\u5728Python\u4e2d\u5c55\u793a\u5462\uff1f<\/p>\n<p>ctrl+s\u4fdd\u5b58\u6587\u4ef6\u5230\u4e00\u4e2a\u5408\u9002\u7684\u9879\u76ee\u5730\u5740\uff0c\u6253\u5f00\u547d\u4ee4\u884c\uff0ccd\u547d\u4ee4\u79fb\u52a8\u5230\u9879\u76ee\u5730\u5740\uff0c\u4fdd\u5b58\u65f6\u4f1a\u5c06\u6570\u636e\u4fdd\u5b58\u4e3a\u4e00\u4e2a.ui\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u6211\u4eec\u4f7f\u7528\u547d\u4ee4\u5c06.ui\u6587\u4ef6\u8fdb\u884c\u8f6c\u5316\u4e3a.py\u6587\u4ef6\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" null=\"\">pyuic5 -o XXXX.py XXXX.ui<\/code>\r\n#XXXX\u4e3a\u4f60\u81ea\u5b9a\u4e49\u7684\u6587\u4ef6\u540d\uff0c\u53ef\u4ee5\u4e24\u8005\u4e0d\u4e00\u6837<\/pre>\n<p>\u6b64\u65f6\u5f97\u5230\u8f6c\u6362\u540e\u7684py\u4ee3\u7801\u6587\u4ef6\uff0c\u4f7f\u7528\u540d\u4e3aUi_MainWindow\u7684\u7c7b\u8868\u793a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" python=\"\"># -*- coding: utf-8 -*-\r\n\r\n# Form implementation generated from reading ui file 'hello.ui'\r\n#\r\n# Created by: PyQt5 UI code generator 5.13.0\r\n#\r\n# WARNING! All changes made in this file will be lost!\r\n\r\n\r\nfrom PyQt5 import QtCore, QtGui, QtWidgets\r\n\r\n\r\nclass Ui_MainWindow(object):\r\n    def setupUi(self, MainWindow):\r\n        MainWindow.setObjectName(\"MainWindow\")\r\n        MainWindow.resize(800, 600)\r\n        self.centralwidget = QtWidgets.QWidget(MainWindow)\r\n        self.centralwidget.setObjectName(\"centralwidget\")\r\n        self.label = QtWidgets.QLabel(self.centralwidget)\r\n        self.label.setGeometry(QtCore.QRect(170, 190, 461, 151))\r\n        font = QtGui.QFont()\r\n        font.setFamily(\"\u96b6\u4e66\")\r\n        font.setPointSize(24)\r\n        self.label.setFont(font)\r\n        self.label.setObjectName(\"label\")\r\n        MainWindow.setCentralWidget(self.centralwidget)\r\n        self.menubar = QtWidgets.QMenuBar(MainWindow)\r\n        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))\r\n        self.menubar.setObjectName(\"menubar\")\r\n        MainWindow.setMenuBar(self.menubar)\r\n        self.statusbar = QtWidgets.QStatusBar(MainWindow)\r\n        self.statusbar.setObjectName(\"statusbar\")\r\n        MainWindow.setStatusBar(self.statusbar)\r\n\r\n        self.retranslateUi(MainWindow)\r\n        QtCore.QMetaObject.connectSlotsByName(MainWindow)\r\n\r\n    def retranslateUi(self, MainWindow):\r\n        _translate = QtCore.QCoreApplication.translate\r\n        MainWindow.setWindowTitle(_translate(\"MainWindow\", \"MainWindow\"))\r\n        self.label.setText(_translate(\"MainWindow\", \"Hello World -- \u4f60\u597d\uff0c\u4e16\u754c\"))\r\n<\/code><\/pre>\n<p>\u522b\u7740\u6025\uff0c\u6b64\u65f6\u4ee3\u7801\u8fd0\u884c\u662f\u6ca1\u6709\u4efb\u4f55\u7ed3\u679c\u7684\uff0c\u6211\u4eec\u9700\u8981\u5c06\u8fd9\u4e2a\u7c7b\u5176\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u52a0\u8f7d\u548c\u8c03\u7528\u624d\u80fd\u6b63\u5e38\u4f7f\u7528\uff0c\u6211\u4eec\u9700\u8981\u65b0\u5efa\u4e00\u4e2apython\u6587\u4ef6\u8fdb\u884c\u5bf9\u4ee3\u7801\u7684\u8c03\u7528\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\" python=\"\">from PyQt5 import QtCore, QtGui, QtWidgets\r\nimport sys\r\nimport hello    #\u4e4b\u524d\u7684\u6587\u4ef6\u540d\u79f0\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u5305\u5bfc\u5165\r\n\r\napp = QtWidgets.QApplication(sys.argv)  # \u521b\u5efa\u4e00\u4e2aQApplication\uff0c\u4e5f\u5c31\u662f\u4f60\u8981\u5f00\u53d1\u7684\u8f6f\u4ef6app\r\nMainWindow = QtWidgets.QMainWindow()    # \u521b\u5efa\u4e00\u4e2aQMainWindow\uff0c\u7528\u6765\u88c5\u8f7d\u4f60\u9700\u8981\u7684\u5404\u79cd\u7ec4\u4ef6\u3001\u63a7\u4ef6\r\nui = hello.Ui_MainWindow()              # ui\u662fUi_MainWindow()\u7c7b\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61\r\nui.setupUi(MainWindow)                  # \u6267\u884c\u7c7b\u4e2d\u7684setupUi\u65b9\u6cd5\uff0c\u65b9\u6cd5\u7684\u53c2\u6570\u662f\u7b2c\u4e8c\u6b65\u4e2d\u521b\u5efa\u7684QMainWindow\r\nMainWindow.show()                       # \u6267\u884cQMainWindow\u7684show()\u65b9\u6cd5\uff0c\u663e\u793a\u8fd9\u4e2aQMainWindow\r\nsys.exit(app.exec_())                   # \u4f7f\u7528exit()\u6216\u8005\u70b9\u51fb\u5173\u95ed\u6309\u94ae\u9000\u51faQApplication\r\n\r\n#\u6ce8\u610f\u7b2c\u4e03\u884c\u7684hello\u4e3a\u4f60\u521b\u5efa\u7684\u7c7b\u540d<\/code><\/pre>\n<p>\u6548\u679c\u8fbe\u6210<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/HOP@EAPP5X6E@IH7Z7-300x163.png\" alt=\"\" width=\"813\" height=\"442\" class=\"alignnone  wp-image-612\" srcset=\"https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/HOP@EAPP5X6E@IH7Z7-300x163.png 300w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/HOP@EAPP5X6E@IH7Z7-768x417.png 768w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/HOP@EAPP5X6E@IH7Z7-1024x557.png 1024w, https:\/\/www.mustenaka.cn\/wp-content\/uploads\/2020\/01\/HOP@EAPP5X6E@IH7Z7.png 1928w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5f00\u59cb\u4e0a\u624bPythonQt\u9879\u76ee\u7684\u5b66\u4e60\uff0c\u5495\u8bb0\u672c\u7b14\u8bb0 \u9996\u5148\u662fPyQt\u7684\u5b89\u88c5\uff0c\u76f4\u63a5pip\u8d70\u8d77 pip i [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,13,43],"tags":[65,31,40],"class_list":["post-608","post","type-post","status-publish","format-standard","hentry","category-python","category-vscode","category-programming-language","tag-pyqt","tag-python","tag-qt"],"views":1329,"_links":{"self":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/comments?post=608"}],"version-history":[{"count":1,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/608\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/608\/revisions\/613"}],"wp:attachment":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/media?parent=608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/categories?post=608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/tags?post=608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}