pyqt5学习
作者:互联网
首先贴出官方文档:https://www.riverbankcomputing.com/static/Docs/PyQt5/sip-classes.html
然后是github上的中文档:https://github.com/maicss/PyQt5-Chinese-tutorial
1 第一个PyQt5程序
1 利用pyqtdesign生成界面源码
利用pyqtdesign生成一个界面程序,然后将之转换为py源代码(这一步网上教程很多,略过)
2 从源码继承我们的逻辑类
CallFirstMainWin.py
from PyQt5.QtWidgets import QMainWindow
from CallFirstMainWin_ui import *
class MyMainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.setupUi(self)
3 写测试代码
main.py
# -*- coding: utf-8 -*_
import sys
from PyQt5.QtWidgets import QApplication
from CallFirstMainWin import MyMainWindow
if __name__ == "__main__":
app = QApplication(sys.argv)
myWin = MyMainWindow()
myWin.show()
sys.exit(app.exec_())
最后附上qtdesign工具生成转换得到的py文件
CallFirstMainWin_ui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'CallFirstMainWin_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# 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
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
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,PyQt5,QtWidgets,学习,pyqt5,import,MainWindow 来源: https://blog.csdn.net/luhouxiang/article/details/120097088