主代码
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