{"id":2700,"date":"2023-09-06T18:08:03","date_gmt":"2023-09-06T10:08:03","guid":{"rendered":"https:\/\/www.tra56.com\/?p=2700"},"modified":"2023-09-06T18:08:03","modified_gmt":"2023-09-06T10:08:03","slug":"2700","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/2700.html","title":{"rendered":"Python PyQt5\u6a21\u5757\u5b9e\u73b0\u7a97\u53e3GUI\u754c\u9762\u4ee3\u7801\u5b9e\u4f8b"},"content":{"rendered":"
PyQt5\u662f\u57fa\u4e8eDigia\u516c\u53f8\u5f3a\u5927\u7684\u56fe\u5f62\u7a0b\u5f0f\u6846\u67b6Qt5\u7684python\u63a5\u53e3\uff0c\u7531\u4e00\u7ec4python\u6a21\u5757\u6784\u6210\u3002PyQt5\u672c\u8eab\u62e5\u6709\u8d85\u8fc7620\u4e2a\u7c7b\u548c6000\u51fd\u6570\u53ca\u65b9\u6cd5\u3002\u5728\u53ef\u4ee5\u8fd0\u884c\u4e8e\u591a\u4e2a\u5e73\u53f0\uff0c\u5305\u62ec\uff1aUnix, Windows, and Mac OS\u3002<\/p>\n
\u4ee3\u7801\u5982\u4e0b<\/p>\n
from PyQt5.QtWidgets import QApplication,QWidget,QProgressBar,QPushButton\r\nfrom PyQt5.QtCore import QBasicTimer\r\nfrom PyQt5.QtGui import QIcon\r\nimport sys\r\n \r\nclass Example(QWidget):\r\n def __init__(self):\r\n super().__init__()\r\n self.initUI() # \u663e\u793a\u7a97\u4f53\u5185\u5bb9\r\n def initUI(self):\r\n self.pbar = QProgressBar(self)\r\n self.pbar.setGeometry(30, 50, 200, 25) #\u8bbe\u7f6e\u8fdb\u5ea6\u6761\u4f4d\u7f6e\u53ca\u5927\u5c0f\r\n self.btn = QPushButton('\u5f00\u59cb', self)\r\n self.btn.move(50, 90)\r\n self.btn.clicked.connect(self.doAction) #\u70b9\u51fb\u6309\u94ae\u65f6\u6267\u884c\u7684\u52a8\u4f5c\u51fd\u6570\u6307\u5b9a\u4e3aself.doAction()\r\n # self.btn.setGeometry(50, 90, 40, 25)\r\n \r\n self.timer = QBasicTimer() #\u6784\u5efa\u4e00\u4e2a\u8ba1\u6570\u5668\r\n self.step = 0 #\u8bbe\u7f6e\u57fa\u6570\r\n self.setGeometry(300, 300, 280, 170) # \u8bbe\u7f6e\u6574\u4e2a\u7a97\u4f53\u7684\u5927\u5c0f\r\n self.setWindowTitle('\u8fdb\u5ea6\u6761') #\u8bbe\u7f6e\u7a97\u53e3\u6807\u9898\r\n # self.setWindowIcon('logo2.png') #\u8bbe\u7f6e\u7a97\u53e3\u56fe\u6807\r\n self.show()\r\n \r\n def timerEvent(self, *args, **kwargs):\r\n if self.step >= 100:\r\n self.timer.stop()\r\n self.btn.setText('\u5b8c\u6210')\r\n return\r\n self.step += 1\r\n self.pbar.setValue(self.step) #timer\u6bcf\u6b21\u91cd\u56f4\u65f6\u5c06self.step \u8d4b\u503c\u7ed9pbar\r\n \r\n \r\n def doAction(self):\r\n if self.timer.isActive():\r\n self.timer.stop()\r\n self.btn.setText('\u5f00\u59cb')\r\n else:\r\n self.timer.start(100, self)\r\n self.btn.setText('\u505c\u6b62')\r\n \r\nif __name__ == '__main__':\r\n app = QApplication(sys.argv) # \u521b\u5efa\u4e00\u4e2aQT\u5e94\u7528\u5bf9\u8c61\r\n ex = Example()\r\n sys.exit(app.exec_())<\/pre>\n\u7ed3\u679c<\/p>\n
<\/p>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
PyQt5\u662f\u57fa\u4e8eDigia\u516c\u53f8\u5f3a\u5927\u7684\u56fe\u5f62\u7a0b\u5f0f\u6846\u67b6Qt5\u7684python\u63a5\u53e3\uff0c\u7531\u4e00\u7ec4python\u6a21\u5757\u6784\u6210\u3002PyQt […]<\/p>\n","protected":false},"author":1,"featured_media":2702,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-2700","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2700"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=2700"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2700\/revisions"}],"predecessor-version":[{"id":2703,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2700\/revisions\/2703"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media\/2702"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=2700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=2700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=2700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}