哇,眼看就要成功了,,界面的切换老是不成功。后面发现是上一个界面还存在在布局中,这里就简单记录一下。详细的后面再写
总而言之言之:删除widget只需要两句话
self.child2是我要删除的widget
self.gridLayout是我的布局名字
self.child2.setParent(None)
self.gridLayout.removeWidget(self.child2)
这是我应用的一部分程序
1.按键链接函数
2.函数把布局中的上一个widget清除
3.添加新的widget
由此点击按键即可进行布局里面widget的切换
self.displaygui_pushButton.clicked[bool].connect(self.displaygui_button) self.setdebug_pushButton.clicked[bool].connect(self.stepdebug_button) def displaygui_button(self): self.child2.setParent(None) self.gridLayout.removeWidget(self.child2) self.gridLayout.addWidget(self.child1) self.child1.show() def stepdebug_button(self): self.child1.setParent(None) self.gridLayout.removeWidget(self.child1) self.gridLayout.addWidget(self.child2) self.child2.show()