pyqt5實現多窗口
主窗口通過按鈕顯示子窗口
1. 使用qtdesigner設計窗口
主窗口:main window
子窗口:Dialog
生成的是ui文件
2. 為兩個窗口生成py文件
3. 創建兩個窗口的繼承類
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())