-1

I'm working on a basic project with using PyQt5. I made a break method so I can close app with pressing a button. I made a loop in this but when I close the window loop doesn't go back. I want to able to close the window without quitting the program fully.

There is 'main' side:

        if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        mainWin = TextBar()
        mainWin.show()
        sys.exit(app.exec_())

And there is button and its command:

pybutton = QPushButton('OK', self)
            pybutton.clicked.connect(self.clickMethod)
            pybutton.resize(200, 32)
            pybutton.move(80, 100)

        def clickMethod(self):
            print('Name: ' + self.tool.text(), '\nProperties:' + self.prop.text(), '\n')
            TextBar.close(self)

I want to close ONLY window when I press OK, NOT full of program.

Dharman
  • 30,962
  • 25
  • 85
  • 135
statist31
  • 25
  • 4
  • Does this answer your question? [How do I execute more code after closing a PyQt window?](https://stackoverflow.com/questions/25005727/how-do-i-execute-more-code-after-closing-a-pyqt-window) – ThePyGuy Jun 03 '21 at 13:41
  • 2
    Please provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – musicamante Jun 03 '21 at 14:38
  • I provided. Is this okay? – statist31 Jun 04 '21 at 18:08

1 Answers1

0

when the Mainwindow is closed nothing should be running, unless you consider hidding it, like

YourQMainWindow.hide()
self.YourQMainWindow.hide()

2-Methode initialize 2 difference instances, like that once one is closed, another remains or, at about to close, your run a second instance

if __name__ == "__main__":
    app = Qtw.QApplication(sys.argv)
    main_window = MainWindow()   #---->first instance
    main_window1 = MainWindow()  #---->second instance
    sys.exit(app.exec())

if you run then both, they take more ressouces, so i suggest you create a button to close the first one, that alse start at the same time the second instance of your app,.... Unless you provide more reproductible example (a piece of code), this is how i can only go in advicing you,...(please confirm if it's working for you, me i always use this technic, & it's working),...thank you

  • I used hide method, thanks. But it doesn't properly now too. I want to go the first step of loop and ask choice of user when I hide/close the window. When I press the button nothing happens except hiding the window. – statist31 Jun 05 '21 at 12:17