内置窗口 pyqt5
1.使用Qt Designer设计三个窗口
注意:在主窗口中需要添加一个girdLayout
2.创建**.py
from PyQt5.QtWidgets import QMainWindow, QApplication from main import Ui_Main from show import Ui_Show from new import Ui_New import sys class Main(QMainWindow,Ui_Main): def __init__(self): super(Main,self).__init__() self.setupUi(self) self.child1 = Show() self.child2 = New() self.action_2.triggered.connect(self.New) self.action.triggered.connect(self.Show) def Show(self): self.gridLayout.addWidget(self.child1)#将窗口放入girdLayout中 self.child1.show()#打开子窗口1 def New(self): self.gridLayout_2.addWidget(self.child2) self.child2.show() class New(QMainWindow,Ui_New): def __init__(self): super(New,self).__init__() self.setupUi(self) self.pushButton.clicked.connect(self.Close) def Close(self): self.close() class Show(QMainWindow,Ui_Show): def __init__(self): super(Show,self).__init__() self.setupUi(self) if __name__=='__main__': app = QApplication(sys.argv) Main = Main() Show = Show() New = New() Main.show() sys.exit(app.exec_())
3.在主窗口里有两个选项(“初始”和“新建”)与两个子窗口关联
4.“初始”打开
5.“新建”打开
###############################################
小技巧
发现出现了两个底边那个东西
在由窗口文件生成的.py文件中找到如下代码
self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar)
或者在Qt Designer设计时找到
删掉任意一个就OK了