Reputation: 1689
I'm writing a PyQt application which needs to get some input before loading the main window. I have set up the following class (minimized):
class MyInput(QWidget):
def __init__(self):
super(MyInput, self).__init__()
self.thing = False
mybutton = QPushButton('Press me', self)
mybutton.clicked.connect(self.set_data)
def set_data(self):
self.hide()
self.destroyLater()
self.thing = True
def get_thing(self):
self.show()
return self.thing
Later, I have this function:
def ask_thing():
mi = MyInput()
return mi.get_thing()
Now, when I call ask_thing()
, I want mi.get_thing()
to wait for the button to be pressed before returning the value (or return False if it is closed). However, self.show()
seems to run separately and lets the code continue executing, hitting the return
statement and leaving the function.
How can I wait for input?
Upvotes: 0
Views: 535
Reputation: 1249
Maybe you have to consider changing from QWidget
to QDialog
. Then change the function show
to exec_
, which will execute the widget waiting user's interaction.
Upvotes: 1