python PYQT5 uic
作者:互联网
uic5
designer.exe
C:\software\ANACONDA3\envs\storm_control\Lib\site-packages\pyqt5_tools 有designer.exe,双击designer.exe 打开pyqt5,拖动控件创建一个ui文件保存在某个文件夹下面,比如。
pyuic5.exe
我们用pyqt5创建了一个新的ui后,我们需要把ui文件转成python文件,pyuic5.exe就是专门干这事的。
pyuic5.exe在C:\software\ANACONDA3\Scripts里面。
cd C:\software\ANACONDA3\Scripts
pyuic5 -x "c:\code\python\UI_test.ui" -o "c:\code\python\UI_test.py"
在相应的文件夹里面,就会生成一个.py,运行此文件就会显示对用的UI,当然也可以查看其代码构造.
from PyQt5 import QtCore, QtGui, QtWidgets
def setupUi(self, MainWindow):
***
self.pushButton.clicked.connect(self.printMessage
self.seletImageBtn.clicked.connect(self.setImage)
self.addBtn.clicked.connect(self.addItem)
def printMessage(self):
print("Hello World!")
def setImage(self):
fileName,_ = QtWidgets.QFileDialog.getOpenFileName(None, "selet Image", "", "Image Files (*.png *.jpg *ipeq *.bmp *.tif)")
if fileName :
pixmap = QtGui.QPixmap(fileName)
pixmap = pixmap.scaled(self.imageLbl.width(), self.imageLbl.height(), QtCore.Qt.KeepAspectRatio)
self.imageLbl.setPixmap(pixmap)
self.imageLbl.setAlignment(QtCore.Qt.AlignCenter)
def addItem(self):
value = self.lineEdit.text()
self.lineEdit.clear()
self.listWidget.addItem(value)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
运行程序为:
参考链接
- https://www.youtube.com/watch?v=ksW59gYEl6Q
标签:__,uic,exe,python,self,PYQT5,ui,MainWindow 来源: https://blog.csdn.net/weixin_40662209/article/details/89742454