0

I am creating a PyQt4 gui that allows the user in a qmainwindow to input some initial parameters and then click a start button to begin a program. When they click the start button, a new window that displays the parameters appears, and the program begins. I would like the user to be able to initiate multiple instances of the program. However, when the parameters are changed in the qmainwindow and the start button is clicked a second time, the first program window disappears.

Is there a way to have the start button call a second window that runs concurrently with the first window? I imagine this would be something like threading, but from what I have read, PyQt4 doesn't seem to have a method for threading within an application.

Any help would be much appreciated.

1 Answers1

3

I am guessing that you are saving the reference to newly created window in the same variable. If you want to create multiple windows, try to save the reference to that window in a separate variable, i.e each window should have it's own reference variable.

def showWindow(self):
    self.child = Window(self)
    self.child.show()

If this is your situation, the first window will loose it's reference as soon as the second time showWindow() executes. Because the self.child will contain the reference to second window, resulting in closing the first window, because the first window has no reference reference. As soon as the widget looses reference in Qt, the widget will be destroyed. To overcome this problem maintain a list of variables:

# declare a list in __init__ as self.widgetList = []

def showWindow(self):
    win = Window(self):
    win.show()
    self.widgetList.append(win)
qurban
  • 3,885
  • 24
  • 36