我想按一个窗口的按钮,然后关上那个窗口,然后打开一个新窗口
我该怎么做?在
我已经试过了,但它会向控制台发送以下消息:
QCoreApplication::exec:事件循环已在运行
class Window(QWidget):
def __init__(self,parent = None):
super().__init__(parent)
self.title = 'pySim Z-eighty'
self.left = 0
self.top = 0
self.width = 1200
self.height = 3000
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.button = QPushButton("Z80")
self.button1 = QPushButton()
self.button2 = QPushButton()
self.container = QWidget()
self.layout = QGridLayout()
self.layout.addWidget(self.button1, 1, 0)
self.layout.addWidget(self.button, 1, 1)
self.layout.addWidget(self.button2, 1, 2)
self.container.setLayout(self.layout)
self.layoutPrincipal = QBoxLayout(0)
self.layoutPrincipal.addWidget(self.container)
self.setLayout(self.layoutPrincipal)
self.button.pressed.connect(self.IniciarInterfaz)
def IniciarInterfaz(self):
self.hide()
app = QApplication(sys.argv)
ex = mainWindow()
ex.setStyleSheet("background-color: #fff")
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Window()
ex.show()
sys.exit(app.exec_())
我的主要问题是当我按下按钮时,我无法打开新窗口
在
PyQt
应用程序中只能有一个QApplication
,因此如果您已经创建了它,请不要再创建它。在另一个问题是变量只存在于上下文中,在你的mainWindow中,所以在函数的末尾StartInterface将消除这个变量和窗口,解决方法是使mainWindow成为类的成员,这样上下文将成为类而不再是函数,所以它将保持正确。在
PYQT无开关方法,。。。在
hide()和show()方法您可以随意使用按钮,。。。在
相关问题 更多 >
编程相关推荐