iPhynx
iPhynx

Reputation: 431

Open a widget with button PyQt5

I have a button connected to a function called OpenSupplyWidget() which is supposed to start a QWidget class I have in another file (the file is SupplyWidget.py and is already imported).

def OpenSupplyWidget(self):
    sw = SupplyWidget()
    sw.show()

The function only opens the window for a split second. Using sys.exit(app.exec_()) only returns an error saying the QApplication event loop is already running.

What method do I use to get what I want (opening a widget)?

Thanks!

Upvotes: 0

Views: 1726

Answers (1)

Aleksi SA
Aleksi SA

Reputation: 36

Try having the SupplyWidget outside of the OpenSupplyWidget-function. The sw probably gets destroyed because the function terminates.

...
def __init__(self):
    self.sw = SupplyWidget()

def OpenSupplyWidget(self):
    self.sw.show()
..

Upvotes: 2

Related Questions