1

I am trying to go into another window by clicking a button from the current window in Python's third party GUI package, PySide.

From the MainWindow class, once the 'Next Window Button' is clicked, it goes to the NewWindow class to create a new window.

The problem is that the new window just pops up for about a second.

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class NewWindow(QWidget):
    def __init__(self):
        super(NewWindow, self).__init__()
        self.LLayout = QGridLayout()
        self.btn2 = QPushButton('Present Window')
        self.LLayout.addWidget(self.btn2)
        self.setLayout(self.LLayout)
        self.setWindowTitle('My SWindow')
        self.show()


class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.WLayout = QGridLayout()
        self.btn = QPushButton('Next Window')
        self.btn.clicked.connect(self.windowfunction)


        self.WLayout.addWidget(self.btn)

        self.setLayout(self.WLayout)
        self.setWindowTitle('My FWindow')
        self.show()

    def windowfunction(self):
        new_window = NewWindow()

def main():
    app = QApplication(sys.argv)
    main = MainWindow()
    sys.exit(app.exec_())

main()
Qudus
  • 1,440
  • 2
  • 13
  • 22

0 Answers0