In new versions, dialog box functionality has been broken

Hi, looks like one of the recent versions broke some of the gui.DLG functionality I have long been using, at least on MacOS (Sonoma 14.6).

It seems the dictionary returned by dlg.show() no longer is in the same format, yielding the keyError shown if you execute the code I have pasted at bottom.

Moreover, while the result of my code used to give a dialog box that looks like this:

It now looks like this, with none of the question text showing any more:

from psychopy import gui
# Collect demographic variables
# Use a gui.Dlg and so you can avoid labeling the cancel button , but can't avoid showing it
# This approach gives more control, eg, text color.
questions = ['What is your age?', 'Which of the following best describes your gender?', 'What is the first language you learned to read?', 'Are you fluent in English?']
dlg = gui.Dlg(title="PatHons", labelButtonOK=u'         OK         ', labelButtonCancel=u'', pos=(200, 400)) # Cancel (decline to answer all)
dlg.addField(questions[0])
dlg.addField(questions[1], choices=[ 'Man','Woman','Trans and/or gender diverse','I use a different term','Decline to answer'])
dlg.addField(questions[2], choices=[ 'English','Arabic','Pali','Hebrew','Farsi','Chinese','Korean','Japanese','Other','Decline to answer'])
dlg.addField(questions[3], choices=[ 'Yes','No','Decline to answer'])
thisInfo = dlg.show()  # you have to call show() for a Dlg (automatic with a DlgFromDict)
    
demographics = {q: 'Decline to answer (pressed unlabeled cancel button)' for q in questions}  #Assume pressed cancel unless get values
if dlg.OK:
    print(thisInfo)
    print( "type of thisInfo=", type(thisInfo), "dir=",dir(thisInfo) )
    print("I think this works prior to 2024.1.5, but now gives a KeyError:", thisInfo[0] )
    demographics = dict([ (questions[0], thisInfo[0]), (questions[1], thisInfo[1]), (questions[2], thisInfo[2]), (questions[3], thisInfo[3])])
#end demographics collection

I’m not sure when between 2023.2.3 and 2024.1.5 it broke (it’s also broken in 2024.2.1).

It looks like there was a change in 2024.1.0 such that the gui dialog system started doing everything with dictionaries rather than lists, including adding fields and storing data: RF: Handle dlg data as a dict · psychopy/psychopy@0b8c718 · GitHub

Notably this includes the fact that “addField” now requires a key when called, and “label” is now an optional argument, rather than the key serving as the label. “addText” is now “addFixedField”.

This was not a well-documented change. The documentation for the gui.dlg function (psychopy.gui - create dialogue boxes — PsychoPy v2024.2.1) provided in the example is no longer viable and needs to be updated. I’ll throw in a github issue about that.

So the dialog declaration in your code needs to be something like:

dlg = gui.Dlg(title="PatHons", labelButtonOK=u'         OK         ', labelButtonCancel=u'', pos=(200, 400)) # Cancel (decline to answer all)
dlg.addField('age', label=questions[0])
dlg.addField('gender', label=questions[1], choices=[ 'Man','Woman','Trans and/or gender diverse','I use a different term','Decline to answer'])
dlg.addField('language',label=questions[2], choices=[ 'English','Arabic','Pali','Hebrew','Farsi','Chinese','Korean','Japanese','Other','Decline to answer'])
dlg.addField('fluent', label=questions[3], choices=[ 'Yes','No','Decline to answer'])
thisInfo = dlg.show()  # you have to call show() for a Dlg (automatic with a DlgFromDict)

And on the other end, you need to refer to each field by its key rather than an index. So,

thisInfo['age']

1 Like