{"id":177433,"date":"2023-08-02T04:54:50","date_gmt":"2023-08-01T20:54:50","guid":{"rendered":"http:\/\/www.idc.net\/help\/177433\/"},"modified":"2023-08-02T04:54:50","modified_gmt":"2023-08-01T20:54:50","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e5%a6%82%e4%bd%95%e5%b0%81%e8%a3%85pyqt5%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/177433\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u5982\u4f55\u5c01\u88c5pyqt5\u7c7b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/image\/967\/795\/954\/1613616487858208.png\" class=\"aligncenter\"><\/p>\n<p><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1;font-size:14px\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1\">\u672c\u6587\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1a<\/span>windows7\u7cfb\u7edf\u3001Python 3.9.1\uff0cDELL G3\u7535\u8111\u3002<\/span><\/p>\n<p><strong>\u4e00\u3001\u4ee3\u7801\u5c01\u88c5\u601d\u8def<\/strong><\/p>\n<p>1.\u5206\u6790\u54ea\u4e9b\u4ee3\u7801\u9700\u8981\u5c01\u88c5\uff1a\u9700\u8981\u5c01\u88c5\u7684\u5c31\u662f\u6211\u4eec\u5bf9\u7a97\u4f53\u914d\u7f6e\u7684\u4ee3\u7801<\/p>\n<p>2.\u5229\u7528\u7c7b\u7684\u7ee7\u627f\u7279\u6027<\/p>\n<p>3.\u8c03\u7528\u7236\u7c7bQwidget\u7684\u6784\u9020\u65b9\u6cd5super().__init__()<\/p>\n<p>4.\u4e0d\u8981\u5fd8\u8bb0\u8c03\u7528\u81ea\u5df1\u672c\u8eab\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5\u521d\u59cb\u5316UI<\/p>\n<p><strong>\u4e8c\u3001GUI\u4f4d\u7f6e\u5927\u5c0f\u51fd\u6570<\/strong><\/p>\n<p>GUI\u4f4d\u7f6e\u5927\u5c0f\u51fd\u6570\u4f7f\u7528setGeometry<\/p>\n<p>\u4f5c\u7528\uff1a\u8fd9\u4e2a\u51fd\u6570\u76f8\u5f53\u4e8eresize\u51fd\u6570\u548cmove\u51fd\u6570\u529f\u80fd\u7684\u5408\u4f53\u3002<\/p>\n<p>\u51fd\u6570\u4f7f\u7528\u683c\u5f0f\uff1a<\/p>\n<p>\u63a7\u4ef6\u5bf9\u8c61.setGeometry\uff08X\u8f74\uff0cY\u8f74,\u5bbd\u5ea6\uff0c\u9ad8\u5ea6\uff09<\/p>\n<p><strong>&nbsp;\u4e09\u3001\u4fe1\u53f7\u76f8\u5173<\/strong><\/p>\n<p>\u7a97\u4f53\u4e0a\u9762\u6240\u6709\u7684\u4fe1\u53f7\u88abapp.exec_()\u6b7b\u5faa\u73af\u76d1\u542c\u7740\u3002<\/p>\n<p>\u4fe1\u53f7\u53ea\u662f\u5728QT\u4e2d\u9488\u5bf9\u53d1\u751f\u4e86\u67d0\u4e2a\u4e8b\u4ef6\u7684\u4e00\u4e2a\u8bf4\u6cd5\u3002<\/p>\n<p>\u69fd\u662fQT\u4e2d\u53d1\u751f\u7684\u5177\u4f53\u7684\u67d0\u4e2a\u4e8b\u4ef6\u6267\u884c\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u7a97\u4f53\u4e0a\u5bf9GUI\u7684\u884c\u4e3a\u90fd\u662f\u67d0\u4e2a\u4e8b\u4ef6\u7684\u884c\u4e3a\uff0cGUI\u662f\u88ab\u4e8b\u4ef6\u9a71\u52a8\u7684\u3002<\/p>\n<p><strong>\u56db\u3001\u6e90\u7801<\/strong><\/p>\n<pre>import&nbsp;sys\nfrom&nbsp;PyQt5.QtWidgets&nbsp;import&nbsp;QWidget,QApplication,QPushButton\n&nbsp;\nclass&nbsp;MyClass(QWidget):\n&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;__init__(self):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super().__init__()\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.initUI()\n&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;initUI(self):\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.setWindowTitle(\"\u5218\u91d1\u7389\u7f16\u7a0b\")\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.setGeometry(30,40,300,200)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;self.resize(300,200)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;self.move(30,40)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btn=QPushButton(\"\u8001\u5218\",self)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btn.move(50,60)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#\u8bbe\u7f6e\u6309\u94ae\u7684\u70b9\u51fb\u540e\u5173\u95ed\u7a97\u4f53\u7684\u4e8b\u4ef6\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btn.clicked.connect(self.close)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.show()\n&nbsp;\nif&nbsp;__name__==\"__main__\":\n&nbsp;&nbsp;&nbsp;&nbsp;app=QApplication(sys.argv)\n&nbsp;&nbsp;&nbsp;&nbsp;mc=MyClass()\n&nbsp;&nbsp;&nbsp;&nbsp;app.exec_()<\/pre>\n<p>\u62d3\u5c55\uff1aPyQt5\u7684\u7c7b<br \/><strong><\/strong><\/p>\n<p>PyQt5\u7684\u7c7b\u5b58\u5728\u4e0e\u5982\u4e0b\u6a21\u5757\u5f53\u4e2d\uff1a<\/p>\n<p>QtCore\u6a21\u5757\u6db5\u76d6\u4e86\u5305\u7684\u6838\u5fc3\u7684\u975eGUI\u529f\u80fd\uff0c\u6b64\u6a21\u5757\u88ab\u7528\u4e8e\u5904\u7406\u7a0b\u5e8f\u4e2d\u6d89\u53ca\u5230\u7684 time\u3001\u6587\u4ef6\u3001\u76ee\u5f55\u3001\u6570\u636e\u7c7b\u578b\u3001\u6587\u672c\u6d41\u3001\u94fe\u63a5\u3001mime\u3001\u7ebf\u7a0b\u6216\u8fdb\u7a0b\u7b49\u5bf9\u8c61\u3002<\/p>\n<p>QtGui\u6a21\u5757\u6db5\u76d6\u591a\u79cd\u57fa\u672c\u56fe\u5f62\u529f\u80fd\u7684\u7c7b; \u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a\u7a97\u53e3\u96c6\u3001\u4e8b\u4ef6\u5904\u7406\u30012D\u56fe\u5f62\u3001\u57fa\u672c\u7684\u56fe\u50cf\u548c\u754c\u9762 \u548c\u5b57\u4f53\u6587\u672c\u3002<\/p>\n<p>QtWidgets\u6a21\u5757\u5305\u542b\u4e86\u4e00\u6574\u5957UI\u5143\u7d20\u7ec4\u4ef6\uff0c\u7528\u4e8e\u5efa\u7acb\u7b26\u5408\u7cfb\u7edf\u98ce\u683c\u7684classic\u754c\u9762\uff0c\u975e\u5e38\u65b9\u4fbf\uff0c\u53ef\u4ee5\u5728\u5b89\u88c5\u65f6\u9009\u62e9\u662f\u5426\u4f7f\u7528\u6b64\u529f\u80fd\u3002<\/p>\n<p>QtMultimedia\u6a21\u5757\u5305\u542b\u4e86\u4e00\u5957\u7c7b\u5e93\uff0c\u8be5\u7c7b\u5e93\u88ab\u7528\u4e8e\u5904\u7406\u591a\u5a92\u4f53\u4e8b\u4ef6\uff0c\u901a\u8fc7\u8c03\u7528API\u63a5\u53e3\u8bbf\u95ee\u6444\u50cf\u5934\u3001\u8bed\u97f3\u8bbe\u5907\u3001\u6536\u53d1\u6d88\u606f\uff08radio functionality\uff09\u7b49\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fpython\u5c01\u88c5pyqt5\u7c7b\u7684\u65b9\u6cd5\uff0c\u5927\u5bb6\u5728\u5bf9\u57fa\u7840\u7684\u5c01\u88c5\u601d\u8def\u7406\u6e05\u540e\uff0c\u53ef\u4ee5\u5c31pyqt5\u7c7b\u8fdb\u884c\u4e00\u4e9b\u5b9e\u9645\u7684\u64cd\u4f5c\uff0c\u5e76\u5728\u4e0b\u4e00\u6b21\u8c03\u7528\u524d\u5c31\u8fdb\u884c\u5c01\u88c5<span style=\"font-size: 16px\">\u3002<span>\u66f4\u591aPython\u9ad8\u7ea7\u6307\u8def\uff1a<\/span><span>python\u540e\u6d6a\u4e91\u6559\u7a0b<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1awindows7\u7cfb\u7edf\u3001Python 3.9.1\uff0cDELL G3\u7535\u8111\u3002 \u4e00\u3001\u4ee3\u7801\u5c01\u88c5\u601d\u8def 1. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":177434,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-177433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/177433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=177433"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/177433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/177434"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=177433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=177433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=177433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}