{"id":1531,"date":"2023-03-15T15:52:25","date_gmt":"2023-03-15T07:52:25","guid":{"rendered":"http:\/\/175.24.184.226\/?p=1531"},"modified":"2023-03-15T15:52:25","modified_gmt":"2023-03-15T07:52:25","slug":"pyqt5%e5%9f%ba%e6%9c%ac%e6%8e%a7%e4%bb%b6%e4%bd%bf%e7%94%a8%e5%8d%95%e9%80%89%e6%8c%89%e9%92%ae%e3%80%81%e5%a4%8d%e9%80%89%e6%a1%86%e3%80%81%e4%b8%8b%e6%8b%89%e6%a1%86%e3%80%81%e6%96%87%e6%9c%ac","status":"publish","type":"post","link":"\/?p=1531","title":{"rendered":"PyQt5\u57fa\u672c\u63a7\u4ef6\u4f7f\u7528\u5355\u9009\u6309\u94ae\u3001\u590d\u9009\u6846\u3001\u4e0b\u62c9\u6846\u3001\u6587\u672c\u6846"},"content":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecdPyQt5\u754c\u9762\u6700\u57fa\u672c\u4f7f\u7528\u7684\u5355\u9009\u6309\u94ae\u3001\u590d\u9009\u6846\u3001\u4e0b\u62c9\u6846\u4e09\u79cd\u63a7\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n<p>1\u3001RadioButton\u5355\u9009\u6309\u94ae\/CheckBox\u590d\u9009\u6846\u3002\u9700\u8981\u77e5\u9053\u5982\u4f55\u5224\u65ad\u5355\u9009\u6309\u94ae\u662f\u5426\u88ab\u9009\u4e2d\u3002<\/p>\n<p>2\u3001ComboBox\u4e0b\u62c9\u6846\u3002\u9700\u8981\u77e5\u9053\u5982\u4f55\u5bf9\u4e0b\u62c9\u6846\u4e2d\u7684\u53d6\u503c\u8fdb\u884c\u8bbe\u7f6e\u4ee5\u53ca\u4ee3\u7801\u5b9e\u73b0\u4e2d\u5982\u4f55\u83b7\u53d6\u7528\u6237\u9009\u4e2d\u7684\u503c\u3002<\/p>\n<p>\u5e26\u7740\u8fd9\u4e9b\u95ee\u9898\u4e0b\u9762\u5f00\u59cb\u4ecb\u7ecd\u8fd9RadioButton\u5355\u9009\u6309\u94ae\u3001CheckBox\u590d\u9009\u6846\u3001ComboBox\u4e0b\u62c9\u6846\u4e09\u79cd\u57fa\u672c\u63a7\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5<\/p>\n<h1>QRadioButton\u5355\u9009\u6309\u94ae<\/h1>\n<p>\u5355\u9009\u6309\u94ae\u4e3a\u7528\u6237\u63d0\u4f9b<strong>\u591a\u9009\u4e00<\/strong>\u7684\u9009\u62e9\uff0c\u662f\u4e00\u79cd\u5f00\u5173\u6309\u94ae\u3002QRadioButton\u5355\u9009\u6309\u94ae\u662f\u5426\u9009\u62e9\u72b6\u6001\u901a\u8fc7isChecked()\u65b9\u6cd5\u5224\u65ad\u3002isChecked()\u65b9\u6cd5\u8fd4\u56de\u503cTrue\u8868\u793a\u9009\u4e2d\uff0cFalse\u8868\u793a\u672a\u9009\u4e2d\u3002<\/p>\n<p><strong>RadioButton\u793a\u4f8b\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python\"># -*- coding: utf-8 -*-\n\nimport sys\nfrom PyQt5 import QtCore, QtGui, QtWidgets\nfrom PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QRadioButton\n\nclass Ui_Form(object):\n    def setupUi(self, Form):\n        Form.setObjectName(&quot;Form&quot;)\n        Form.resize(309, 126)\n        self.radioButton = QtWidgets.QRadioButton(Form)\n        self.radioButton.setGeometry(QtCore.QRect(70, 40, 89, 16))\n        self.radioButton.setObjectName(&quot;radioButton&quot;)\n        self.okButton = QtWidgets.QPushButton(Form)\n        self.okButton.setGeometry(QtCore.QRect(70, 70, 75, 23))\n        self.okButton.setObjectName(&quot;okButton&quot;)\n\n        self.retranslateUi(Form)\n        QtCore.QMetaObject.connectSlotsByName(Form)\n\n    def retranslateUi(self, Form):\n        _translate = QtCore.QCoreApplication.translate\n        Form.setWindowTitle(_translate(&quot;Form&quot;, &quot;RadioButton\u5355\u9009\u6309\u94ae\u4f8b\u5b50&quot;))\n        self.radioButton.setText(_translate(&quot;Form&quot;, &quot;\u5355\u9009\u6309\u94ae&quot;))\n        self.okButton.setText(_translate(&quot;Form&quot;, &quot;\u786e\u5b9a&quot;))\n\nclass MyMainForm(QMainWindow, Ui_Form):\n    def __init__(self, parent=None):\n        super(MyMainForm, self).__init__(parent)\n        self.setupUi(self)\n        self.okButton.clicked.connect(self.checkRadioButton)\n\n    def checkRadioButton(self):\n        if self.radioButton.isChecked():\n            QMessageBox.information(self,&quot;\u6d88\u606f\u6846\u6807\u9898&quot;,&quot;\u6211RadioButton\u6309\u94ae\u88ab\u9009\u4e2d\u5566\uff01&quot;,QMessageBox.Yes | QMessageBox.No)\n\nif __name__ == &quot;__main__&quot;:\n    app = QApplication(sys.argv)\n    myWin = MyMainForm()\n    myWin.show()\n    sys.exit(app.exec_())<\/code><\/pre>\n<p><strong>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/774327-20190803104343702-1153275014.png\" alt=\"img\" \/><\/p>\n<p><strong>\u5173\u952e\u4ee3\u7801\u4ecb\u7ecd\uff1a<\/strong><\/p>\n<p><strong>self.radioButton.isChecked()<\/strong> --&gt; \u7528\u4e8e\u5224\u65adRadioButton\u63a7\u4ef6\u662f\u5426\u88ab\u9009\u4e2d\u3002\u8fd4\u56de\u503cTrule\u8868\u793a\u6309\u94ae\u88ab\u9009\u4e2d\uff0cFalse\u8868\u793a\u6309\u94ae\u672a\u9009\u4e2d\u3002<\/p>\n<h1>QCheckBox\u590d\u9009\u6846<\/h1>\n<p>\u590d\u9009\u6846\u548c\u5355\u9009\u6309\u94ae\u4e00\u6837\u90fd\u662f\u9009\u9879\u6309\u94ae\uff0c\u533a\u522b\u662f\u590d\u9009\u6846\u4e3a\u7528\u6237\u63d0\u4f9b<strong>\u591a\u9009\u591a<\/strong>\u7684\u9009\u62e9\u3002\u590d\u9009\u6846\u6309\u94ae\u540c\u6837\u662f\u4f7f\u7528isChecked()\u65b9\u6cd5\u5224\u65ad\u662f\u5426\u88ab\u9009\u4e2d\u3002<\/p>\n<p><strong>CheckBox\u4f8b\u5b50\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python\"># -*- coding: utf-8 -*-\n\nimport sys\nfrom PyQt5 import QtCore, QtGui, QtWidgets\nfrom PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QCheckBox\n\nclass Ui_Form(object):\n    def setupUi(self, Form):\n        Form.setObjectName(&quot;Form&quot;)\n        Form.resize(380, 154)\n        self.freshcheckBox = QtWidgets.QCheckBox(Form)\n        self.freshcheckBox.setGeometry(QtCore.QRect(50, 40, 71, 31))\n        font = QtGui.QFont()\n        font.setPointSize(14)\n        self.freshcheckBox.setFont(font)\n        self.freshcheckBox.setObjectName(&quot;freshcheckBox&quot;)\n        self.bearcheckBox = QtWidgets.QCheckBox(Form)\n        self.bearcheckBox.setGeometry(QtCore.QRect(140, 40, 71, 31))\n        font = QtGui.QFont()\n        font.setPointSize(14)\n        self.bearcheckBox.setFont(font)\n        self.bearcheckBox.setObjectName(&quot;bearcheckBox&quot;)\n        self.okButton = QtWidgets.QPushButton(Form)\n        self.okButton.setGeometry(QtCore.QRect(230, 40, 71, 31))\n        font = QtGui.QFont()\n        font.setPointSize(14)\n        self.okButton.setFont(font)\n        self.okButton.setObjectName(&quot;okButton&quot;)\n\n        self.retranslateUi(Form)\n        QtCore.QMetaObject.connectSlotsByName(Form)\n\n    def retranslateUi(self, Form):\n        _translate = QtCore.QCoreApplication.translate\n        Form.setWindowTitle(_translate(&quot;Form&quot;, &quot;CheckBox\u4f8b\u5b50&quot;))\n        self.freshcheckBox.setText(_translate(&quot;Form&quot;, &quot;\u9c7c&quot;))\n        self.bearcheckBox.setText(_translate(&quot;Form&quot;, &quot;\u718a\u638c&quot;))\n        self.okButton.setText(_translate(&quot;Form&quot;, &quot;\u786e\u5b9a&quot;))\n\nclass MyMainForm(QMainWindow, Ui_Form):\n    def __init__(self, parent=None):\n        super(MyMainForm, self).__init__(parent)\n        self.setupUi(self)\n        self.okButton.clicked.connect(self.checkCheckBox)\n\n    def checkCheckBox(self):\n        if self.freshcheckBox.isChecked() and self.bearcheckBox.isChecked():\n            QMessageBox.information(self,&quot;\u6d88\u606f\u6846\u6807\u9898&quot;,&quot;\u9c7c\u548c\u718a\u638c\u6211\u8981\u517c\u5f97\uff01&quot;,QMessageBox.Yes | QMessageBox.No)\n\nif __name__ == &quot;__main__&quot;:\n    app = QApplication(sys.argv)\n    myWin = MyMainForm()\n    myWin.show()\n    sys.exit(app.exec_())<\/code><\/pre>\n<p><strong>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/774327-20190803105955429-341890867.png\" alt=\"img\" \/><\/p>\n<p><strong>\u5173\u952e\u4ee3\u7801\u4ecb\u7ecd\uff1a<\/strong><\/p>\n<p><strong>self.freshcheckBox.isChecked() and self.bearcheckBox.isChecked() --&gt;<\/strong> \u540c\u6837\u9002\u7528isChecked()\u51fd\u6570\u5224\u65ad\u3002<\/p>\n<h1>QComboBox\u4e0b\u62c9\u5217\u8868\u6846<\/h1>\n<p>\u4e0b\u62c9\u5217\u8868\u6846\u662f\u4e00\u4e2a\u96c6\u6309\u94ae\u548c\u4e0b\u62c9\u9009\u9879\u4e8e\u4e00\u4f53\u7684\u63a7\u4ef6\u3002\u901a\u5e38\u7528\u4e8e\u56fa\u5b9a\u7684\u679a\u4e3e\u503c\u4f9b\u7528\u6237\u9009\u62e9\u65f6\u4f7f\u7528\u3002\u5bf9\u4e8e\u4e0b\u62c9\u5217\u8868\u6846\u7684\u4f7f\u7528\u6700\u57fa\u672c\u7684\u662f\u8981\u77e5\u9053\u5982\u4f55\u6dfb\u52a0\u4e0b\u62c9\u5217\u8868\u6846\u4e2d\u7684\u503c\u4ee5\u53ca\u5982\u4f55\u83b7\u53d6\u4e0b\u62c9\u6846\u4e2d\u9009\u62e9\u7684\u503c\u3002<\/p>\n<p>\uff081\uff09<strong>\u5982\u4f55\u6dfb\u52a0\u4e0b\u62c9\u5217\u8868\u6846\u4e2d\u7684\u503c\u3002<\/strong><\/p>\n<p>1\u3001\u4f7f\u7528addItem() \u6dfb\u52a0\u4e00\u4e2a\u4e0b\u62c9\u9009\u9879\u6216\u8005additems() \u4ece\u5217\u8868\u4e2d\u6dfb\u52a0\u4e0b\u62c9\u9009\u9879 \u65b9\u6cd5\u8fdb\u884c\u6dfb\u52a0\u3002<\/p>\n<p>2\u3001\u5982\u679c\u4f7f\u7528Qt Designer\u753b\u56fe\u5b9e\u73b0\uff0c\u53ef\u4ee5\u5c06ComboBox\u63a7\u4ef6\u6dfb\u52a0\u5230\u4e3b\u754c\u9762\u540e\u53cc\u51fb\u4e0b\u62c9\u5217\u8868\u6846\u8fdb\u884c\u6253\u5f00\u6dfb\u52a0\u3002\u5982\u4e0b\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/774327-20190803110632141-2107466794.png\" alt=\"img\" \/><\/p>\n<p><strong>\uff082\uff09\u5982\u4f55\u83b7\u53d6\u4e0b\u62c9\u6846\u4e2d\u7684\u53d6\u503c<\/strong><\/p>\n<p>\u4f7f\u7528\u51fd\u6570currentText() \u8fd4\u56de\u9009\u9879\u4e2d\u7684\u6587\u672c\u8fdb\u884c\u83b7\u53d6<\/p>\n<p><strong>ComboBox\u793a\u4f8b\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python\"># -*- coding: utf-8 -*-\n\nimport sys\nfrom PyQt5 import QtCore, QtGui, QtWidgets\nfrom PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QComboBox\n\nclass Ui_Form(object):\n    def setupUi(self, Form):\n        Form.setObjectName(&quot;Form&quot;)\n        Form.resize(400, 130)\n        self.comboBox = QtWidgets.QComboBox(Form)\n        self.comboBox.setGeometry(QtCore.QRect(80, 50, 69, 22))\n        self.comboBox.setObjectName(&quot;comboBox&quot;)\n        self.comboBox.addItem(&quot;&quot;)\n        self.comboBox.addItem(&quot;&quot;)\n        self.comboBox.addItem(&quot;&quot;)\n        self.comboBox.addItem(&quot;&quot;)\n        self.okButton = QtWidgets.QPushButton(Form)\n        self.okButton.setGeometry(QtCore.QRect(190, 50, 75, 23))\n        self.okButton.setObjectName(&quot;okButton&quot;)\n\n        self.retranslateUi(Form)\n        QtCore.QMetaObject.connectSlotsByName(Form)\n\n    def retranslateUi(self, Form):\n        _translate = QtCore.QCoreApplication.translate\n        Form.setWindowTitle(_translate(&quot;Form&quot;, &quot;ComboBox\u4e0b\u62c9\u6846\u4f8b\u5b50&quot;))\n        self.comboBox.setItemText(0, _translate(&quot;Form&quot;, &quot;Python&quot;))\n        self.comboBox.setItemText(1, _translate(&quot;Form&quot;, &quot;C++&quot;))\n        self.comboBox.setItemText(2, _translate(&quot;Form&quot;, &quot;Go&quot;))\n        self.comboBox.setItemText(3, _translate(&quot;Form&quot;, &quot;Java&quot;))\n        self.okButton.setText(_translate(&quot;Form&quot;, &quot;\u786e\u5b9a&quot;))\n\nclass MyMainForm(QMainWindow, Ui_Form):\n    def __init__(self, parent=None):\n        super(MyMainForm, self).__init__(parent)\n        self.setupUi(self)\n        self.okButton.clicked.connect(self.getComboxBoxValue)\n\n    def getComboxBoxValue(self):\n        select_value = self.comboBox.currentText()\n        QMessageBox.information(self,&quot;\u6d88\u606f\u6846\u6807\u9898&quot;,&quot;\u4f60\u8981\u5b66%s,\u4e3a\u5e08\u7ed9\u4f60\u8bf4\u9053\u8bf4\u9053\uff01&quot; % (select_value,),QMessageBox.Yes | QMessageBox.No)\n\nif __name__ == &quot;__main__&quot;:\n    app = QApplication(sys.argv)\n    myWin = MyMainForm()\n    myWin.show()\n    sys.exit(app.exec_())<\/code><\/pre>\n<p><strong>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/774327-20190803111506531-784673945.png\" alt=\"img\" \/><\/p>\n<p><strong>\u5173\u952e\u4ee3\u7801\u4ecb\u7ecd\uff1a<\/strong><\/p>\n<p>select_value = self.comboBox.currentText() --&gt; \u4f7f\u7528currentText()\u51fd\u6570\u83b7\u53d6\u4e0b\u62c9\u6846\u4e2d\u9009\u62e9\u7684\u503c<\/p>\n<h1>\u6587\u672c\u6846\u63a7\u4ef6\uff08QLineEdit\u3001QTextEdit\uff09<\/h1>\n<p>\u6587\u672c\u6846\u63a7\u4ef6\u5206\u4e3a\u5355\u884c\u6587\u672c\u6846\uff08QLineEdit\uff09\u548c\u591a\u884c\u6587\u672c\u6846\uff08QTextEdit\uff09\u3002\u5355\u884c\u6587\u672c\u6846\u53ea\u5141\u8bb8\u8f93\u5165\u4e00\u884c\u5b57\u7b26\u4e32\u3002\u591a\u884c\u6587\u672c\u6846\u53ef\u4ee5\u663e\u793a\u591a\u884c\u6587\u672c\u5185\u5bb9\uff0c\u5f53\u6587\u672c\u5185\u5bb9\u8d85\u51fa\u63a7\u4ef6\u663e\u793a\u8303\u56f4\u65f6\uff0c\u53ef\u4ee5\u663e\u793a\u6c34\u5e73\u548c\u5782\u76f4\u6eda\u52a8\u6761\u3002<\/p>\n<p>\u9488\u5bf9\u6587\u672c\u6846\u63a7\u4ef6\uff0c\u8fd9\u91cc\u4e3b\u8981\u4e86\u89e3\u6587\u672c\u6846\u5185\u5bb9\u7684\u8bbe\u7f6e\u3001\u83b7\u53d6\u4ee5\u53ca\u6e05\u9664\u4e09\u79cd\u4e3b\u8981\u65b9\u6cd5\u3002\u5355\u884c\u6587\u672c\u6846\u548c\u591a\u884c\u6587\u672c\u6846\u7684\u8bbe\u7f6e\u548c\u83b7\u53d6\u65b9\u6cd5\u4e0d\u540c\uff0c\u5982\u4e0b\u3002<\/p>\n<p><strong>\u5355\u884c\u6587\u672c\u6846\uff08QLineEdit\uff09\u65b9\u6cd5\u5982\u4e0b\uff1a<\/strong><\/p>\n<p>setText()\uff1a\u8bbe\u7f6e\u5355\u884c\u6587\u672c\u6846\u5185\u5bb9\u3002<\/p>\n<p>Text():\u8fd4\u56de\u6587\u672c\u6846\u5185\u5bb9<\/p>\n<p>clear()\uff1a\u6e05\u9664\u6587\u672c\u6846\u5185\u5bb9<\/p>\n<p><strong>\u591a\u884c\u6587\u672c\u6846\uff08QTextEdit\uff09\u65b9\u6cd5\u5982\u4e0b\uff1a<\/strong><\/p>\n<p>setPlainText()\uff1a\u8bbe\u7f6e\u591a\u884c\u6587\u672c\u6846\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n<p>toPlainText()\uff1a\u83b7\u53d6\u591a\u884c\u6587\u672c\u6846\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n<p>clear()\uff1a\u6e05\u9664\u591a\u884c\u6587\u672c\u6846\u7684\u5185\u5bb9<\/p>\n<p><strong>\u6587\u672c\u6846\u4f7f\u7528\u5b9e\u4f8b\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python\"># -*- coding: utf-8 -*-\n\nimport sys\nfrom PyQt5 import QtCore, QtGui, QtWidgets\nfrom PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QComboBox\n\nclass Ui_Form(object):\n    def setupUi(self, Form):\n        Form.setObjectName(&quot;Form&quot;)\n        Form.resize(411, 314)\n        self.lineEdit = QtWidgets.QLineEdit(Form)\n        self.lineEdit.setGeometry(QtCore.QRect(120, 50, 251, 41))\n        self.lineEdit.setObjectName(&quot;lineEdit&quot;)\n        self.lineedit_label = QtWidgets.QLabel(Form)\n        self.lineedit_label.setGeometry(QtCore.QRect(10, 60, 81, 20))\n        font = QtGui.QFont()\n        font.setPointSize(11)\n        font.setBold(True)\n        font.setWeight(75)\n        self.lineedit_label.setFont(font)\n        self.lineedit_label.setObjectName(&quot;lineedit_label&quot;)\n        self.textEdit = QtWidgets.QTextEdit(Form)\n        self.textEdit.setGeometry(QtCore.QRect(120, 120, 251, 141))\n        self.textEdit.setObjectName(&quot;textEdit&quot;)\n        self.textedit_label = QtWidgets.QLabel(Form)\n        self.textedit_label.setGeometry(QtCore.QRect(13, 180, 81, 31))\n        font = QtGui.QFont()\n        font.setPointSize(11)\n        font.setBold(True)\n        font.setWeight(75)\n        self.textedit_label.setFont(font)\n        self.textedit_label.setObjectName(&quot;textedit_label&quot;)\n        self.run_Button = QtWidgets.QPushButton(Form)\n        self.run_Button.setGeometry(QtCore.QRect(150, 280, 91, 31))\n        font = QtGui.QFont()\n        font.setPointSize(11)\n        font.setBold(True)\n        font.setWeight(75)\n        self.run_Button.setFont(font)\n        self.run_Button.setObjectName(&quot;run_Button&quot;)\n\n        self.retranslateUi(Form)\n        QtCore.QMetaObject.connectSlotsByName(Form)\n\n    def retranslateUi(self, Form):\n        _translate = QtCore.QCoreApplication.translate\n        Form.setWindowTitle(_translate(&quot;Form&quot;, &quot;TextEdit_Example&quot;))\n        self.lineedit_label.setText(_translate(&quot;Form&quot;, &quot;LineEdit&quot;))\n        self.textedit_label.setText(_translate(&quot;Form&quot;, &quot;TextEdit&quot;))\n        self.run_Button.setText(_translate(&quot;Form&quot;, &quot;Run&quot;))\n\nclass MyMainForm(QMainWindow, Ui_Form):\n    def __init__(self, parent=None):\n        super(MyMainForm, self).__init__(parent)\n        self.setupUi(self)\n        self.run_Button.clicked.connect(self.set_display_edit)\n\n    def set_display_edit(self):\n        #\u8bbe\u7f6e\u524d\u5148\u6e05\u9664\u6587\u672c\u5185\u5bb9\n        self.lineEdit.clear()\n        self.textEdit.clear()\n\n        #\u8bbe\u7f6e\u6587\u672c\u6846\u5185\u5bb9\n        self.lineEdit.setText(&quot;Lineedit contents&quot;)\n        self.textEdit.setPlainText(&quot;Textedit contents&quot;)\n\n        #\u83b7\u53d6\u6587\u672c\u6846\u5185\u5bb9\uff0c\u5e76\u5f39\u6846\u663e\u793a\u5185\u5bb9\n        str1 = self.lineEdit.text()\n        str2 = self.textEdit.toPlainText()\n        QMessageBox.information(self,&quot;\u83b7\u53d6\u4fe1\u606f&quot;,&quot;LineEdit\u6587\u672c\u6846\u5185\u5bb9\u4e3a:%s,TextEdit\u6587\u672c\u6846\u5185\u5bb9\u4e3a\uff1a%s&quot; %(str1,str2))\n\nif __name__ == &quot;__main__&quot;:\n    app = QApplication(sys.argv)\n    myWin = MyMainForm()\n    myWin.show()\n    sys.exit(app.exec_())<\/code><\/pre>\n<p><strong>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><strong><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/774327-20190914081307356-2097616620.png\" alt=\"img\" \/><\/strong><\/p>\n<p><strong>\u5173\u952e\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code class=\"language-python\">    def set_display_edit(self):\n        #\u8bbe\u7f6e\u524d\u5148\u6e05\u9664\u6587\u672c\u5185\u5bb9\n        self.lineEdit.clear()\n        self.textEdit.clear()\n\n        #\u8bbe\u7f6e\u6587\u672c\u6846\u5185\u5bb9\n        self.lineEdit.setText(&quot;Lineedit contents&quot;)\n        self.textEdit.setPlainText(&quot;Textedit contents&quot;)\n\n        #\u83b7\u53d6\u6587\u672c\u6846\u5185\u5bb9\uff0c\u5e76\u5f39\u6846\u663e\u793a\u5185\u5bb9\n        str1 = self.lineEdit.text()\n        str2 = self.textEdit.toPlainText()\n        QMessageBox.information(self,&quot;\u83b7\u53d6\u4fe1\u606f&quot;,&quot;LineEdit\u6587\u672c\u6846\u5185\u5bb9\u4e3a:%s,TextEdit\u6587\u672c\u6846\u5185\u5bb9\u4e3a\uff1a%s&quot; %(str1,str2))<\/code><\/pre>\n<h1>\u5c0f\u7ed3<\/h1>\n<p>RadioButton\u5355\u9009\u6309\u94ae\u3001CheckBox\u590d\u9009\u6846\u3001ComboBox\u4e0b\u62c9\u6846\u4e09\u79cd\u57fa\u672c\u63a7\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u4ecb\u7ecd\u5b8c\u4e86\u3002\u672c\u6587\u4e2d\u7684\u5185\u5bb9\u548c\u5b9e\u4f8b\u4e5f\u57fa\u672c\u56de\u7b54\u4e86\u5f00\u7bc7\u63d0\u5230\u7684\u95ee\u9898\u3002\u8fd9\u4e09\u79cd\u57fa\u672c\u63a7\u4ef6\u7684\u4f7f\u7528\u7b80\u5355\u4f46\u4e5f\u5f88\u9891\u7e41\u3002\u53ef\u4ee5\u591a\u52a8\u624b\u5b9e\u8df5\u4e00\u4e0b\u3002\u4e0a\u6587\u4e2d\u7684\u7a0b\u5e8f\u90fd\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u3002\u53ef\u4ee5\u8fd0\u884c\u770b\u770b\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecdPyQt5\u754c\u9762\u6700\u57fa\u672c\u4f7f\u7528\u7684\u5355\u9009\u6309\u94ae\u3001\u590d\u9009\u6846\u3001\u4e0b\u62c9\u6846\u4e09\u79cd\u63a7\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u8fdb\u884c\u4ecb\u7ecd\u3002 1\u3001RadioButton\u5355\u9009\u6309\u94ae\/Chec   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[132],"tags":[133,16],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1531"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1531"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1531\/revisions"}],"predecessor-version":[{"id":1532,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1531\/revisions\/1532"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1531"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}