Domanda

I did a small script on python to do some stuff, and I want to ask user input first. This is my current code:

import sys
from PySide import QtGui

app = QtGui.QApplication(sys.argv)
gui = QtGui.QWidget()
text, ok = QtGui.QInputDialog.getText(gui, "question",
            """please put the thing I need from you""")
print(text, ok)
if ok:
    app.exit()
else:
    app.exit()
app.exec_()
print ("I'm aliveeeee'")

The dialog pop-ups exactly as I want, but app.exec_() never ends so the rest of the code is never executed (and the process never finish) I tried to kill it with app.exit(), app.quit(), I also try to show() and close() the QWidget, but nothing is working.

If I do gui.show() before calling the QInputDialog and then close the widget manually, the app closes successfully. However, this is not the behavior I want.

Can you guide me on which is the best way to close the exec loop after I got my data?

PD: This is going to be a windows app (with py2exe) and using the shell is not an option.

È stato utile?

Soluzione

Just don't call app.exec_()

The problem here is that this is a toy example. In real life, usually you will show some UI and then call app.exec() to let the user interact with it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top