1、安装下载PyQt5
2、Python3.5.4+PyCharm64位还需要下载pyqt5-tools
3、PyCharm配置PyQt5 参考链接
https://blog.csdn.net/yhhyhhyhhyhh/article/details/62886194
4、PyQt5中文教程
http://code.py40.com/pyqt5/16.html
5、PyQt5使用教程
https://blog.csdn.net/shangxiaqiusuo1/article/details/81035046
6、.ui转成的.py代码
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(140, 110, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(140, 170, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(250, 110, 241, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(250, 170, 241, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(140, 220, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(140, 270, 431, 251))
self.label.setFrameShape(QtWidgets.QFrame.Box)
self.label.setText("")
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "打开"))
self.pushButton_2.setText(_translate("MainWindow", "打开"))
self.pushButton_3.setText(_translate("MainWindow", "对比"))
7、新建.py文件然后引用
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
from pyqttest.test import Ui_MainWindow
class mwindow(QMainWindow,Ui_MainWindow):
def __init__(self):
super(mwindow, self).__init__()
self.setupUi(self)
def openimage(self):
self.lineEdit.setText("haha")
def openimage2(self):
self.lineEdit_2.setText("haha2")
def showImage(self):
self.label.setText("haha3")
if __name__ == '__main__':
app = QApplication(sys.argv)
w = mwindow()
w.pushButton.clicked.connect(w.openimage)
w.pushButton_2.clicked.connect(w.openimage2)
w.pushButton_3.clicked.connect(w.showImage)
w.show()
sys.exit(app.exec_())
8、效果图