| Reference | Downloads | Github

Change position of gui.Dlg()

I am using the standalone version of psychopy v1.85.3.

I have a large numbers of variables in my dialogue box and consequently the box is more at the bottom of my screen than in the middle. The class that I am using is:

psychopy.gui.Dlg(title=u'PsychoPy Dialog', pos=None, size=None, style=None, labelButtonOK=u' OK ', labelButtonCancel=u' Cancel ', screen=-1).

I read that there is no way to change the size of the dialogue box (, but could I maybe change the position of the dialogue box? Simply changing the pos variable in does not do the trick.

Here is my code:

from psychopy import gui


expName = 'MTS_Kirst'
# variables for the info dialogue:
# addField(label ='', initial='', color ='', choices=None, tip='', enabled=True)
expInfo_keyDefault = [
                ('participant','','',None, 'participant name or code'),
                ('sex',None,'',('male','female', 'non-binary')),
                ('age','JJ','', None,'age of the participant in years'),
                ('nRuleSwitch_3C1', '1', '', None, 'for every n in nRuleSwitch both rules will be presented once in phase ThreeComparisons1')
                ] # my actual list is longer than that, so that the resulting dialogue box touches the bottom of the monitor

dlg = gui.Dlg(title='Analogy_Kirst', pos=(0, 5)) # the change of pos does not lead to any change in the position of the dialogue

for keyDefault in expInfo_keyDefault:
    # add headings
    if keyDefault[0] == 'participant':
        dlg.addText('Subject Info', color = 'blue')
    elif keyDefault[0] == 'nRuleSwitch':
        dlg.addText('Experiment Options', color = 'blue')
    # add fields
    dlg.addField(*keyDefault) # the splat operator passes the values of the tuple to the function

expInfo_values = # returns a list with all the values; NOT a dict, so the keys are not included

If the user cancels (rather than pressing OK), then the dictionary remains unchanged.
If you want to check whether the user hit OK,
then check whether DlgFromDict.OK equals True or False.
if dlg.OK == False:
    core.quit()  # user pressed cancel

expInfo_keys = [i[0] for i in expInfo_keyDefault]
expInfo = dict(zip(expInfo_keys, expInfo_values))

Thank you for your help :slight_smile:

Have you actually tried setting a value for the pos parameter?

Yes, I have tried that and it didn’t work. :confused: I should have mentioned that. :slight_smile: I now added the code to my original post.

Looking at the code for, the pos argument indeed never seems to get used. It looks like the location is specified in line 318 below, based on the screen centre:

If you are willing to get your hands dirty, you could edit your copy of that file to say:

centerPoint = self.pos

and let us know what happens (I’m flying entirely blind here, and have no idea if this will work or if it will cause some errors). If it does work, I suspect you’d need to specify the pos variable in terms of pixel coordinates rather than in any of PsychoPy’s richer variety of units.

1 Like

Thank you for your reply. :slight_smile:

Unfortunately, I got an error message “permission denied”, when I tried to edit the file “”.

In the end, I just split up my dialogue box in several boxes, which I displayed one after the other.

You haven’t specified your operating system, but it is likely that you simply need administrator privileges to edit that file.

Copy out of where it is to anywhere under your user folder, for example the desktop. Change the name of the version in the original location to Edit your copied version then put it back in the same directory as Your OS will prompt you to enter an admin password as needed.

Alternately, change permissions on the file/directory, make a backup copy of the orginal, edit the file in place, then set permissions back when done. Right-clicking and getting info/properties should lead you to a gui interface for that on OS X/Windows, respectively. There is probably some similar Linux GUI equivalent to that, or you can sudo chmod to change permissions from the command line in Linux/OS X

PyQt and PySide are capable substitutes in case you ever hit a wall with psychopy gui.

I could not find this bug where the position argument is ignored in the list of issues at GitHub so I filed a new one here, linking to this thread.



1 Like

Sounds good. That would be a good one for someone to fix who’s new to the PsychoPy project (won’t be too hard) preferably in both the wx and PyQt engines. I’ll provide a couple more pointers in the github issue that Allen raised

Did this get resolved? I have a similar issue