主窗口:main window
子窗口:Dialog
生成的是ui文件
from PyQt5.QtWidgets import *
from mainwindow import * #mainwindow为子窗口py文件名
from childwindow import * #childwindow为子窗口py文件名
#子窗口继承类
class childWindow(QDialog, Ui_Dialog):
def __init__(self):
super(ParaWindow, self).__init__()
self.setupUi(self)
#主窗口继承类
class mainwindow(QtWidgets.QMainWindow,Ui_MainWindow):
def __init__(self):
super(mywindow,self).__init__()
self.setupUi(self)
#可在继承类中定义其他绑定事件及其对应的函数
#主窗口通过按钮显示子窗口
if __name__ == ‘__main__‘:
app =QtWidgets.QApplication(sys.argv)
main_window = mainwindow()
child_window = childWindow()
main_window.pushButton.clicked.connect(child_window.show)#绑定主窗口的按钮事件为显示子窗口
main_window.show()
sys.exit(app.exec())
原文:https://www.cnblogs.com/DarlingT/p/12676823.html