I am working on a script and I need to ask the user some parameters. I am using the function input:
option1 = input("Bla bla")
option2 = input("Bla bla")
option3 = input("Bla bla")
The first input is working but the following ones don’t. What I am doing wrong?
Same code works outside the function.
You can use a nice GUI widget to get additional inputs.
For a single input you can do this:
result = qt.QInputDialog().getText(None, "Some Title","Some description")
If you need multiple inputs then you can put together a dialogbox with a few fields in 10-15 lines of Python code; or create a dialog in Qt Designer (menu: Edit / Application settings / Developer / Qt Designer → launch):
You can display the dialog and get the entered values like this:
widget = slicer.util.loadUI(r'c:\D\S4\Base\QTGUI\Resources\UI\qSlicerSettingsUserInformationPanel.ui')
ui = slicer.util.childWidgetVariables(widget)
This widget does not have an OK/Cancel button but you can add them in Qt Designer.
We could also look into overriding the
raw_input built-in function to display a dialog when running without
That said, to be robust, modules should provide default values and nicely handle the case of being executed as self-test.