Pyqt5学习(学习中)
1搭建环境
安装pyqt5
在线安装
pip install pyqt5
离线下载+安装
pip download pyqt5 -d save_path
pip install
安装QtDesigner
下载地址:Qt Designer Download for Windows and Mac
ui转python
pyuic5 -x mydesign.ui -o mydesign.py
可以将QtDesigner ,pyuic5加入到pycharm,详见Python - PyQt6、QDesigner、pyuic5-tool 安装使用_sipbuild.pyproject.pyprojectoptionexception-CSDN博客
2.使用
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '0one.ui'
#
# Created by: PyQt5 UI code generator 5.15.11
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QMainWindow, QApplication
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(100, 200, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
import sys
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
self.ui=Ui_Form()
self.ui.setupUi(self)
app=QApplication(sys.argv)
window=MainWindow()
window.show()
sys.exit(app.exec())