windows+pycharm
pip install PyQt5
pip install PyQt5-tools
配置PyCharm是为了在Pycharm里面实现打开qt designer,然后生成qt文件,然后将qt文件转换成python语言的软件文件。
选择File->Settings->Tools->External Tools->点击+
Name:自定义 ,自己认识就好
Program:指向上述安装PyQt5-tools里面的designer.exe,designer.exe这个文件找不到的话就在pyqt5_tools下全局搜索一下,因为这个的存放位置在以前是在pyqt5_tools目录下,现在放在Qt/bin/下,所以全局搜索一下最稳妥
Work directory:使用变量 $FileDir$
Name:自定义 ,自己认识就好
Program:python的安装路径的python.exe路径
Arguments: -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
Work directory:使用变量 $FileDir$
点击Tools->External Tools->Qt Designer
保存退出
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication,QMainWindow
import sys
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(130, 200, 75, 23))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(50, 90, 291, 61))
self.label.setObjectName("label")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
self.pushButton.clicked.connect(self.slot_btn_clicked)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.label.setText(_translate("Form", "TextLabel"))
def slot_btn_clicked(self):
self.label.setText("hello world!!!")
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_Form()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
pyqt5的学习可以看这个:https://github.com/PyQt5/PyQt
原因:pyqt5的plugins路径找不到
解决方案:
QT_QPA_PLATFORM_PLUGIN_PATH
C:\Users\45906\AppData\Local\Programs\Python\Python37\Lib\site-packages\pyqt5_tools\Qt\bin\plugins