Problem with exam project

Hi, making exam project and keep running into the same error messages, my psychopy experiment stops after the dialog box, and cannot find the problem. i post my code and the error message that i get, hope someone can help :))

##import packages
from psychopy import visual, event, core, gui, data
import pandas as pd
import random
import glob

##create popup
dialog = gui.Dlg(title = “First Semester Exam”)
dialog.addField("Participant ID: ")
dialog.addField("Age: ")
dialog.addField("Gender: ", choices=[“Female”, “Male”, “Other”])
dialog.addField("Mood today (1 = in a very bad mood, 5 = in a very good mood): ", choices=[“1”, “2”, “3”, “4”, “5”]) #mood
dialog.addField(“Do you have English as your second language?”, choices=[“Yes”, “No”]) #language

if dialog.OK:
ID =[0]
age =[1]
gender =[2]
mood =[3]
language =[4]
elif dialog.Cancel:

##creating csv file
date = data.getDateStr()
logfile = pd.DataFrame(columns = [“id”, “age”, “gender”, “mood”, “language”, “happy/disgust”, “label/laden”, “word”, “primed/satiated”, “congruent/incongruent”, “response_time”]) #setting all columns for csv, are they good?

##setting up stopwatch and window and fixation cross
win = visual.Window(color=‘black’, size=(1920, 1080))
stopwatch = core.Clock()
fix_cross = visual.TextStim(win, text=‘+’, color=‘white’, height=40)

##getting in the pictures
happy_images = glob.glob(“stimuli/happy*.JPG”)
disgust_images = glob.glob(“stimuli/disgust*.JPG”)

##function for showing words
def stimulus(word, repetition, images):
msg = visual.TextStim(win, text = word)
for _ in range(repetition):
msg = visual.TextStim(win, text = word)
pic = visual.ImageStim(win, image = images[0])
key = event.waitKeys(keyList = [“1”, “9”])
response = stopwatch.getTime()
return response

tryout = [“happyness”,30,“happy_images”]
stimulus(tryout[0], tryout[1], tryout[1])

#setting variables
emotion = “”
connection = “”
repetition = “”
matching = “”
if (tryout[2] == happy_images):
emotion = “happy”
emotion = “disgust”
if (tryout[0] == “joy” or tryout[0] == “happyness” or tryout[0] == “disgust” or tryout[0] == “repulse”):
connection = “label”
connection = “laden”
if (tryout[1] == 3):
repetition = “primed”
repetition = “satiated”
if (((tryout[0] == “joy” or tryout[0] == “happyness” or tryout[0] == “celebration” or tryout[0] == “sunshine”) and tryout[2] == happy_images) or ((tryout[0] == “stink” or tryout[0] == “infection” or tryout[0] == “disgust” or tryout[0] == “repulse”) and tryout[2] == disgust_images)):
matching = “congruent”
matching = “incongruent”

logfile = logfile.append({
“id”: ID,
“age”: age,
“gender”: gender,
“mood”: mood,
“language”: language,
“happy/disgust”: emotion,
“label/laden”: connection,
“word” : tryout[0],
“primed/satiated”: repetition,
“congruent/incongruent”: matching,
“response_time”: response}, ignore_index = True)


##saving csv
logfile_name = “logfiles/logfile_{}_{}.csv”.format(ID, date)

and error message:

Welcome to PsychoPy3!
######## Running: C:\Users\sari\Documents\aarhus\cogcom\exam\ ########
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
C:\Program Files\PsychoPy\lib\site-packages\ UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.4
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Traceback (most recent call last):
Hello from the pygame community. Contribute - pygame wiki
8.3340 WARNING Monitor specification not found. Creating a temporary one…
File “C:\Users\sari\Documents\aarhus\cogcom\exam\”, line 34, in
fix_cross = visual.TextStim(win, text=‘+’, color=‘white’, height=40)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 230, in init
self.setText(text, log=False)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 390, in setText
setAttribute(self, ‘text’, text, log)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\”, line 134, in setAttribute
setattr(self, attrib, value)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\”, line 27, in set
newValue = self.func(obj, value)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 381, in text
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 399, in _setTextShaders
self.pygletTextObj = pyglet.text.Label(
File "C:\Program Files\PsychoPy\lib\site-packages\pyglet\text_init
.py", line 456, in init
self.document.set_style(0, len(self.document.text), {
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 603, in set_style
return super(UnformattedDocument, self).set_style(
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 512, in set_style
self.dispatch_event(‘on_style_text’, start, end, attributes)
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\”, line 418, in dispatch_event
if handler(*args):
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 1073, in on_style_text
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 1043, in _init_document
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 966, in _update
lines = self._get_lines()
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 942, in _get_lines
glyphs = self._get_glyphs()
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\text\”, line 1085, in _get_glyphs
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\font\”, line 394, in get_glyphs
self.glyphs[c] = glyph_renderer.render(c)
File “C:\Program Files\PsychoPy\lib\site-packages\pyglet\font\”, line 444, in render
gdiplus.GdipGraphicsClear(self._graphics, 0x00000000)
OSError: exception: access violation writing 0x000001744631C340
################# Experiment ended with exit code 1 [pid:5996] #################

Hi. I am not an expert on PsychoPy, so bear with me.

So, it looks like you’re encountering an access violation error while trying to write to a specific memory address, which is indicated by the 0x000001744631C340 part of the error message. This could be caused by a number of different issues, such as trying to write to a read-only section of memory or attempting to access memory that has already been freed.

Are you just using the coding screen and not the builder? If so, this would explain your problem. Coder is not recommended as you can encounter serious issues, which are hard to solve. The advice I often see on here, and that has helped me, even for people who use PsychoPy often, is to use the builder screen and insert a code snippet into the code component at the right place (so, before the experiment, begin the experiment, begin routine, every frame, end routine, end experiment).

I recommend first trying that and redoing your experiment with the builder and inserting ‘special code’ via the code component and see how you are. If you are still having issues, come back again. You can still use the coding thread to talk about coding issues, as these code snippets are still code.

If you are new, I recommend checking PsychoPy YouTube channel with demos and the support documentation page to get you started with the builder.

Good Luck :slight_smile: