从pyqt5中的窗口打开第二个窗口时出现问题

时间:2019-07-04 02:29:05

标签: python python-3.x pyqt5

我正在尝试在打开的窗口中创建一个按钮,将其关闭,然后打开新的“ AddStudent”窗口。我相信问题的具体出在addStudentButton和addStudent方法。

我正在使用thonny,并且尝试了所有可以找到的东西,包括self.close()和self.hide,以关闭打开的窗口,但无济于事。我也无法弄清楚如何打开新窗口。

import sys
from PyQt5 import QtWidgets as qt, QtGui
import AddStudent as AS

class OpeningWindow(qt.QMainWindow):


    def __init__(self):
        # Create the window
        super().__init__()

        # Set the window to the dimensions of the Screen
        screenSize = qt.QDesktopWidget().screenGeometry(-1)
        self.height = screenSize.height()
        self.width  = screenSize.width()
        self.setGeometry(0, 0, self.width, self.height)

        # Add the buttons
        self.addStudentButton();

        # Display the GUI
        self.setWindowTitle("All Encompassing Program")
        self.show()

    # Main Buttons
    def addStudentButton(self):
        self.addB = qt.QPushButton(self)
        self.addB.setText("Add New Student")
        self.addB.setGeometry(10, 10, 400, 400)
        self.addB.clicked.connect(self.addStudent)

    def addStudent(self):
        self.AS = AS.AddStudent()
        self.AS.show()
        self.hide() 

app = qt.QApplication(sys.argv)
window = OpeningWindow()
sys.exit(app.exec())



# NEW FILE #

import sys
from PyQt5 import QtWidgets as qt, QtGui

class AddStudent(qt.QMainWindow):

    def __init__(self):
        # Set the window to the dimensions of the Screen
        screenSize = qt.QDesktopWidget().screenGeometry(-1)
        self.height = screenSize.height()
        self.width  = screenSize.width()
        self.window.setGeometry(0, 0, self.width, self.height)

        # Add the buttons

        # Display the GUI
        self.setWindowTitle("Add Student")
        self.show()

它将打开第一个窗口,但是当我按下按钮打开新窗口时,出现错误:

“ QCoreApplication :: exec:事件循环已在运行 后端终止(返回码:4294967295) 使用“停止/重新启动”重新启动后端...”

0 个答案:

没有答案