Hello. I'm new to python.
At university, I'm making a presentation program that reads a PNG format file in a folder named images, shuffles it, and displays it randomly, but after presenting the presented images, another folder (image = used). I want to remodel it so that it can be moved to a folder named). What kind of code should I add to the code below? I also want to be able to set a limit on the number of times. Run with psychopy.
from psychopy import visual, core, event import random, pathlib import csv import glob
if name == 'main':
stimuli_list = glob.glob('images/*.PNG')
for filename in stimuli_list: with open(filename, 'r') as input: random.shuffle (stimuli_list); # Randomize the order print (stimuli_list); # Display random order
current_folder = pathlib.Path (__ file__) .parent # Identify the folder containing the running program new_filename = "results_presented_stimuli.csv" # Use new filename in program with name new_filename new_filepath = current_folder / new_filename # specify new file path datafile = open (new_filepath, mode ='w') # create new file
win = visual.Window() fixation_stim = visual.TextStim (win, "+") # Notepoint no_trials = 0 # initialization of no_trials
for stim in stimuli_list: fixation_stim.draw () #Drawing the gaze point win.flip () #Display the gazing point resp = event.waitKeys (keyList = ['space','q','return']) #Waiting for space key input if resp == ['q']: Exit when #q is entered break stimulus = visual.ImageStim (win, stim) #Preparation for image stimulation stimulus.draw () #Draw image stimulus win.flip () #Display image stimulus core.wait(1.5) no_trials = no_trials + 1 data ='{}, {} \ n'.format (no_trials, stim) # Comma-separated strings datafile.write (data) # Write to file
datafile.close () # close the file win.close()
Recommended Posts