Hi, I’m trying out the GUI for entering custom fields. Specifically, I want some fields to be mandatory, and users should not proceed (and will need to recomplete the dialogue) without filling every required field.
I saw there seem to be two options:
- Add an asterisk to the field label
- set
required=TruewhenaddField
I tried both in my code, but neither seems to successfully emit error/warning. Below is my test code run on PsychoPy 2025.2.4. I simply pressed OK all the time without entering anything:
from psychopy import gui
dlg = gui.Dlg("test")
dlg.addField("label1", required=True)
dlg.addField("label2")
dlg.show()
dlg.validate()
print(dlg.data)
dlg = gui.Dlg("test")
dlg.addField("label1*")
dlg.addField("label2")
dlg.show()
dlg.validate()
print(dlg.data)
>>> {‘label1’: ‘’, ‘label2’: ‘’}
>>> {‘label1*’: ‘’, ‘label2’: ‘’}
As you can see, I also found a validate() method and tried to call it, but it also doesn’t change the outcome at all. I could write a manual test of value myself but prefer the native solution. Would appreciate if someone can explain the expected input format and behavior (raise error? re-do dialogue?)