I need the user to input a value. I'm using input() on qgis python console, but getting this error:
RuntimeError: input(): lost sys.stdin
How can I solve it?
I need the user to input a value. I'm using input() on qgis python console, but getting this error:
RuntimeError: input(): lost sys.stdin
How can I solve it?
from PyQt5.QtWidgets import QInputDialog
def getTextInput(title, message):
answer = QInputDialog.getText(None, title, message)
if answer[1]:
print(answer[0])
return answer[0]
else:
return None
To ask for a user input in QGIS-Console, you can use a QDialog object. There are some kinds of "ready to use" dialogs you could choose from. One of them is QInputDialog which itself can be shown with different types of widgets to get users choice. Above I used the Method getText() which opens a dialog with a single line input. Please read the doc to get more informations about that.
You also can call QInputDialog directly in the Python console:
answer = QInputDialog().getText(None, "Input", "Your input:")
answer is always a tuple like (text, ok) to examine, if input was cancelled and what input was made.