Contents
环境配置
1. 安装pip3:
| 1 2 | sudo apt-get install python3-pip  | 
2. 使用pip安装QT5和工具:
| 1 2 3 | pip3 install  pyqt5 pip3 install  pyqt5-tools | 
3. 安装qtdesigner:
| 1 2 | sudo apt-get install qt5-default qttools5-dev-tools | 
4.校验QT是否安装成功
- 
先测试以下代码 12345678from PyQt5 import QtWidgets, QtGuiimport sysapp = QtWidgets.QApplication(sys.argv)window = QtWidgets.QWidget();window.show()sys.exit(app.exec_())
- 
在终端输入designer尝试启动编辑器 
Demo
1. 界面
打开designer,添加一个lineEdit(文本框)和一个pushButton(按钮),保存为ui文件。

2. 运行以下脚本,将ui文件转为py文件
| 1 2 | python3 -m PyQt5.uic.pyuic untitled.ui -o untitled.py | 
3. demo代码
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # -*- coding: UTF-8 -*- from PyQt5 import QtCore, QtGui, QtWidgets import sys import socket from untitled import Ui_Dialog class query_window(QtWidgets.QMainWindow):     def __init__(self):         QtWidgets.QMainWindow.__init__(self)         self.ui = Ui_Dialog()         self.ui.setupUi(self)         self.ui.pushButton.clicked.connect(self.button_onclick) # 绑定点击事件     def button_onclick(self):         txt = self.ui.lineEdit.text() # 获取文本框的内容         print(txt) if __name__ == '__main__':     app = QtWidgets.QApplication(sys.argv)     window = query_window()     window.show()     sys.exit(app.exec_()) | 
