码迷,mamicode.com
首页 > 其他好文 > 详细

4. PyQt5-实现显示和业务逻辑分离

时间:2019-02-10 17:39:37      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:push   ade   widgets   ase   author   uil   rect   文件   slot   

  • Author: Notus(hehe_xiao@qq.com)
  • Create: 2019-02-10
  • Update: 2019-02-10

PyQt5 实现显示和业务逻辑分离, 继承主界面文件的主窗口类

环境

操作系统: Windows 10 专业版 64-bit (10.0, Build 16299) (16299.rs3_release.170928-1534)
Python Version: 3.7.1
PyQt5 Version: 5.11.3
Qt Designer Version: 5.11.2

界面代码如下(firstMainWin.py)

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file ‘firstMainWin.ui‘
#
# Created by: PyQt5 UI code generator 5.11.3
#
# 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(220, 160, 141, 51))
        self.pushButton.setObjectName("pushButton")
        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", "haha"))
        self.pushButton.setText(_translate("MainWindow", "PushPush"))

主要逻辑代码如下

‘‘‘
    PyQt5 实现显示和业务逻辑分离, 继承主界面文件的主窗口类
    @Author: Notus(hehe_xiao@qq.com)
    @Create: 2019-02-10
    @Update: 2019-02-10
‘‘‘

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from firstMainWin import *

class MyMainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.setupUi(self)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWin = MyMainWindow()
    myWin.show()
    sys.exit(app.exec_())

运行后显示效果如下图

技术图片

4. PyQt5-实现显示和业务逻辑分离

标签:push   ade   widgets   ase   author   uil   rect   文件   slot   

原文地址:https://www.cnblogs.com/leo1875/p/10359575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!