PYQT5子窗口关闭时主窗口调用函数

主代码

from ui_user import Ui_Dialog
from PyQt5.QtWidgets import QApplication, QMainWindow
from exit import My_Exit_Window
import sys


class My_Main_Window(QMainWindow, Ui_Dialog):
    '''主程序'''
    def __init__(self):
        super(My_Main_Window, self).__init__()
        self.setupUi(self)

    def btn(self):
        self.exit_window = My_Exit_Window()
        # 接受子窗口传回来的信号  然后调用主界面的函数
        self.exit_window.my_Signal.connect(self.active_exit)
        self.exit_window.show()

    def active_exit(self):
        self.label.setText('子窗口被关闭')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_window = My_Main_Window()
    main_window.show()
    sys.exit(app.exec_())

在这里插入图片描述

子窗口代码

from ui_exit import Ui_Dialog
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
from PyQt5 import QtCore


class My_Exit_Window(QMainWindow, Ui_Dialog):
    '''主程序'''
    def __init__(self):
        super(My_Exit_Window, self).__init__()
        self.setupUi(self)

    # 让多窗口之间传递信号 刷新主窗口信息
    my_Signal = QtCore.pyqtSignal(str)

    def sendEditContent(self):
        content = '1'
        self.my_Signal.emit(content)

    def closeEvent(self, event):
        self.sendEditContent()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_window = My_Exit_Window()
    main_window.show()
    sys.exit(app.exec_())

在这里插入图片描述

点击关闭,主窗口调用函数active_exit

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值