PyQt
第一个GUI应用例子
1.使用Python 的GUI设计工具Qt Designer(QT设计师)创建用户界面
2.依据功能需求布局小部件(widgets)
3.使用IDE设计工具Eric6导入UI设计文件(.ui编译成.py)
4.对界面编辑生成的py文件进行应用改写
- 使用QT设计师创建如下界面
- 小部件功能介绍
- Label widget(Label 部件)常用功能介绍
1. setText() : This method assigns text to the Label widget
2. setNum() : This method assigns an integer or double value to the Label widget
3. clear() : This method clears text from the Label widget - Line Edit widget 常用功能介绍
- maxLength() : This method is used to specify the maximum length of text that can be entered in the Line Edit widget.
- setText() : This method is used for assigning text to the Line Edit widget.
- text() : This method accesses the text entered in the Line Edit widget.
- clear() : This method clears or deletes the complete content of the Line Editwidget.
- setFocus() : This method positions the cursor on the specified Line Editwidget.
- Push Buttonwidget 常用功能介绍
- setText() : This method is used to assign text to the push button
- setIcon() : This method is used to assign an icon to the push button
- Label widget(Label 部件)常用功能介绍
- 使用IDE工具导入UI设计文件
- 编写应用程序
class MyForm(QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.dispmessage)
self.show()
def dispmessage(self):
self.ui.label_2.setText("Hello "+self.ui.textEdit.toPlainText())
if __name__=="__main__":
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())
- 运行py文件进行功能验证