NotImplementedError после преобразования .py файла в .exe с использованием cx_Freezer: Невозможно выполнить эту операцию для незарегистрированного типа загрузчика. - PullRequest
0 голосов
/ 10 мая 2018

Я создал программу, основанную на «Stroop task» (своего рода психологический тест).Я использовал персидские слова в нем от Unicodes, и в связи с этим мне пришлось использовать библиотеки 'arabic_reshaper' и 'bidict'.Программа отлично работает в Eclipse, но когда я конвертирую его в исполняемый файл, возникает много проблем и ошибок!После использования битов справки, таких как (https://github.com/pyinstaller/pyinstaller/issues/2162) и ( PyInstaller в 32-битном Linux - ImportError: требуется пакет из шести) ), наконец, возникает NotImplementedError, которая показана ниже:

C:\Users\DELL\eclipse-workspace\farsi\Stroop Test\build\exe.win32-3.6>Stroop
Fatal Python error: (pygame parachute) Segmentation Fault
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36-32\lib\site- 
package
s\pygame\pkgdata.py", line 50, in getResource
if resource_exists(pkgname, identifier):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36-32\lib\site- 
package
s\pkg_resources\__init__.py", line 1160, in resource_exists
return get_provider(package_or_requirement).has_resource(resource_name)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36-32\lib\site- 
package
s\pkg_resources\__init__.py", line 1626, in has_resource
return self._has(self._fn(self.module_path, resource_name))
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36-32\lib\site- 
package
s\pkg_resources\__init__.py", line 1681, in _has
"Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader 
type

Теперь я не знаю, что мне нужно сделать, чтобы это исправить. Пожалуйста, помогите мне, мне действительно нужна эта программа для моей диссертации. Вот мои setup.py и скрипты. Я знаю, что коды пишутся неловко, потому чтоЯ не программист, я студент психологии!

import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl86t.lib"
os.environ['TK_LIBRARY'] = "C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tk86t.lib"
executables = [cx_Freeze.Executable("Stroop.py", icon = "stroopicon.ico")]

cx_Freeze.setup(name="STROOP TEST",
                options={"build_exe": {"packages":["pygame"] ,"include_files":["BNazanin_1.ttf","times.txt" , "keyboard.png"]}},executables = executables, version= "1.0")

скрипт:

import pygame
import bidict
import arabic_reshaper
import winsound
import datetime
import time
from _operator import index


pygame.init()
window = pygame.display.set_mode((1280,720))
pygame.display.set_caption("Stroop Test")

madgray = (110,110,110)
gray = (193,205,205)
gray2 = (183,183,183)
alarm_red = (205,0,0)
red = (255,0,0)
green =(118,238,0)
alarm_green = (102,205,0)
black = (0,0,0)
blue2 = (16,78,139)
blue1 = (0,0,139)
blue = (0,0,255)
white = (255,255,255)
yellow = (238,238,0)


i = -1
j = 0
step = -1
stimuli_counter = 0
answer_counter = 0
correct_answer_counter = 0
correct = 0
uncorrect = 0
rctrl_time = 0
lctrl_time = 0
freq_correct = 2000
duration_correct = 50
freq_uncorrect = 1000
duration_uncorrect = 700
freq_alarm = 4000
duration_alarm = 10
running_number = 0

text_red = u'\u0642\u0631\u0645\u0632'
text_blue = u'\u0622\u0628\u0649'
text_green = u'\u0633\u0628\u0632'
text_white = u'\u0633\u0641\u064A\u062F'
text_dorost = u'\u062F\u0631\u0633\u062A'
text_nadorost =u'\u0646\u0627\u062F\u0631\u0633\u062A'
text_shomare_azmoon = u'\u0634\u0645\u0627\u0631\u0647\u0020\u0622\u0632\u0645\u0648\u0646'
text_tamam = u'\u0648\u0642\u062A\u0020\u062A\u0645\u0627\u0645'

r_text_red = arabic_reshaper.reshape(text_red)
r_text_blue = arabic_reshaper.reshape(text_blue)
r_text_green = arabic_reshaper.reshape(text_green)
r_text_white = arabic_reshaper.reshape(text_white)
r_text_dorost = arabic_reshaper.reshape(text_dorost)
r_text_nadorost = arabic_reshaper.reshape(text_nadorost)
r_text_shomare_azmoon = arabic_reshaper.reshape(text_shomare_azmoon)
r_text_tamam = arabic_reshaper.reshape(text_tamam)

from bidi.algorithm import get_display
dr_text_red = get_display(r_text_red)
dr_text_blue = get_display(r_text_blue)
dr_text_green = get_display(r_text_green)
dr_text_white = get_display(r_text_white)
dr_text_dorost = get_display(r_text_dorost)
dr_text_nadorost = get_display(r_text_nadorost)
dr_text_shomare_azmoon = get_display(r_text_shomare_azmoon)
dr_text_tamam = get_display(r_text_tamam)

first_font = pygame.font.Font('BNazanin_1.ttf',100)
seconde_font = pygame.font.Font('BNazanin_1.ttf', 30)
third_font = pygame.font.SysFont('time new roman',60)
fourt_font = pygame.font.SysFont('time new roman',25)
fifth_font = pygame.font.SysFont('time new roman',35)

text1 = third_font.render('Stroop Test', True,blue1,gray)
text2 = fourt_font.render('. Stroop test program',True,black,gray)
text3 = fourt_font.render('. Version 1.0 - May 2018',True,black,gray)
text4 = fourt_font.render('. Developed by Ali Bahari, M.S. in Clinical Psychology, Kharazmi University, Tehran',True,black,gray)
text5 = fifth_font.render('-- Press S to Start', True,blue2,gray)
text6 = fifth_font.render('-- During the test Press T to refresh timing', True,blue2,gray)
text7 = fifth_font.render('-- During the test Press E to exit', True,blue2,gray)
text8 = fifth_font.render('-- Press Esc to exit the program', True,blue2,gray)
text9 = first_font.render(dr_text_tamam,True,red,gray)

text_red_red = first_font.render(dr_text_red, True,red,madgray)
text_red_blue = first_font.render(dr_text_red, True,blue,madgray) 
text_red_green = first_font.render(dr_text_red, True,green,madgray)
text_red_white = first_font.render(dr_text_red, True,white,madgray)
text_red_black = first_font.render(dr_text_red, True,black,madgray)

text_blue_red = first_font.render(dr_text_blue, True,red,madgray)
text_blue_blue = first_font.render(dr_text_blue, True,blue,madgray)
text_blue_green = first_font.render(dr_text_blue, True,green,madgray)
text_blue_white = first_font.render(dr_text_blue, True,white,madgray)
text_blue_black = first_font.render(dr_text_blue, True,black,madgray)

text_green_red = first_font.render(dr_text_green, True,red,madgray)
text_green_blue = first_font.render(dr_text_green, True,blue,madgray)
text_green_green = first_font.render(dr_text_green, True,green,madgray)
text_green_white = first_font.render(dr_text_green, True,white,madgray)
text_green_black = first_font.render(dr_text_green, True,black,madgray)

text_white_red = first_font.render(dr_text_white, True,red,madgray)
text_white_blue = first_font.render(dr_text_white, True,blue,madgray)
text_white_green = first_font.render(dr_text_white, True,green,madgray)
text_white_white = first_font.render(dr_text_white, True,white,madgray)
text_white_black = first_font.render(dr_text_white, True,black,madgray)



stimuli_lib = [text_red_red, text_red_blue, text_red_green, text_red_white,
                text_blue_red, text_blue_blue,text_blue_green, text_blue_white,
                 text_green_red, text_green_blue, text_green_green, text_green_white,
                  text_white_red, text_white_blue, text_white_green, text_white_white]

answer_lib = [text_red_black, text_blue_black, text_green_black, text_white_black]

correct_answer_lib = [0,1]

correct_answer_changer = [0,0,0,0,0,1,0,0,0,0,0,
                          0,0,0,0,0,1,1,1,1,1,0,
                          0,0,1,1,1,1,0,0,0,0,0,
                          0,0,0,1,0,0,0,0,1,1,1,
                          0,0,0,0,1,1,0,0,0,0,0,
                          0,0,0,0,0,0,0,1,1,0,1,
                          1,0,0,0,0,1,0,0,0,1,0,
                          0,0,0,0,1,0,0,1,0,1,1,
                          0,1,0,1,0,0,0,0,0,0,0,
                          0,0,1,1,0,1,0,0,0,1,0,
                          0,0,0,1,0,1,0,0,0,0,0,
                          0,1,0,0,1,1,0,0,0,0,1,
                          1,0,1,0,0,0,0,0,0,0,0,
                          0,0,0,1,1,1,0,0,0,0,0,0]

stimuli_changer = [2,13,11,9,3,14,8,12,4,1,6,
                   7,2,8,12,6,7,4,14,13,11,9,
                   1,3,12,2,8,14,6,9,11,1,4,
                   3,7,13,14,11,1,8,13,3,9,6,
                   7,4,2,12,9,8,2,11,4,12,13,
                   6,7,1,3,14,7,4,12,13,8,9,
                   11,2,14,3,6,1,6,13,2,3,11,
                   1,14,4,7,8,12,9,3,14,12,13,
                   1,2,7,11,8,4,9,6,13,12,14,
                   7,9,3,6,8,4,11,2,1,4,12,
                   2,7,9,1,3,6,11,14,8,13,8,
                   6,4,9,1,13,11,7,12,2,14,3,
                   8,12,11,13,14,2,6,1,3,4,9,
                   7,12,3,11,8,1,14,6,13,7,9,4]

answer_changer = [1,3,1,0,1,2,3,1,3,2,1,
                  2,1,2,3,1,3,0,2,1,3,2,
                  3,2,0,2,0,2,1,3,0,2,1,
                  2,1,3,2,1,0,1,2,3,1,2,
                  0,3,0,2,1,0,3,2,3,1,2,
                  0,2,3,1,3,0,1,0,1,3,1,
                  3,1,3,1,3,1,0,3,1,3,0,
                  3,1,2,1,0,1,0,3,1,0,1,
                  3,2,0,3,2,1,0,1,2,3,1,
                  2,0,3,2,3,0,1,0,3,0,1,
                  3,1,2,1,0,2,1,0,3,0,1,
                  3,0,3,2,1,3,2,1,0,1,3,
                  0,2,3,0,1,0,1,0,2,1,0,
                  1,2,0,3,0,1,3,0,2,1,0,1]

key_image = pygame.image.load('keyboard.png')

input = open('times.txt','r')
input.seek(0)
t1 = input.readline()
input.seek(5)
t2 = input.readline()
input.seek(9)
t3 = input.readline()
t1 = float(t1)
t2 = float(t2)
t3 = float(t3)

start_time = time.time()
threehundred = start_time + t1


gameloop = True
while gameloop :

    for event in pygame.event.get():

        if (event.type == pygame.QUIT):
                gameloop = False

        if (event.type == pygame.KEYDOWN):
            if (event.key == pygame.K_ESCAPE):
                gameloop = False

        if (event.type == pygame.KEYDOWN):
            if (event.key == pygame.K_e):
                i = -1
                step = -1     

        if (event.type == pygame.KEYDOWN):
            if (event.key == pygame.K_t):           
                start_time = time.time()
                threehundred = start_time + t1
                stimuli_counter = 0
                answer_counter = 0
                correct_answer_counter = 0
                correct = 0
                uncorrect = 0

        if step == -1 :
            window.fill(gray)
            window.blit(text1, (640 - text1.get_width() //2, 100 )) 
            window.blit(text2, (100,200 ))
            window.blit(text3, (100,220 ))
            window.blit(text4, (100,240 ))
            window.blit(text5, (300,350 )) 
            window.blit(text6, (300,400 ))
            window.blit(text7, (300,450 ))
            window.blit(text8, (300,500 ))                  
            pygame.display.flip()
            start_time = time.time()
            threehundred = start_time + t1
            stimuli_counter = 0
            answer_counter = 0
            correct_answer_counter = 0
            correct = 0
            uncorrect = 0

            if (event.type == pygame.KEYDOWN):
                if (event.key == pygame.K_s):
                    step += 1 
                    i += 1
                    running_number += 1

        if i == 0 :

            stimuli_stage = stimuli_changer[stimuli_counter]
            stimuli_text_to_show = stimuli_lib[stimuli_stage]
            answer_stage = answer_changer[answer_counter]
            answer_text_to_show = answer_lib[answer_stage]
            correct_answer_stage = correct_answer_changer[correct_answer_counter]
            correct_answer = correct_answer_lib[correct_answer_stage]

            correct_text = seconde_font.render('{0}'.format(correct), True,gray,madgray)
            uncorrect_text = seconde_font.render('{0}'.format(uncorrect), True,gray,madgray)
            dorost_text_to_show = seconde_font.render(dr_text_dorost, True,black,madgray)
            nadorost_text_to_show = seconde_font.render(dr_text_nadorost, True,black,madgray)
            shomare_azmoon_to_show = seconde_font.render('{0} = {1}'.format(running_number, dr_text_shomare_azmoon), True,gray,madgray)

            current_time = threehundred - time.time()
            current_time = round(current_time)
            current_time_text = seconde_font.render('{0}'.format(current_time), True,gray,madgray)

            if current_time <= 0 :
                window.fill(gray) 
                window.blit(text9, (640 - text9.get_width() //2, 360- text9.get_height()//2))         
                pygame.display.flip()
                time.sleep(2)
                step = -1
                i = -1

            if current_time <= t2 and current_time > t3 :
                time_box_color = yellow
                time_box_thikness = 6
            elif current_time <= t3 :
                time_box_color = alarm_red
                time_box_thikness = 8
            else:
                time_box_color = black
                time_box_thikness = 4

            window.fill(madgray)          
            pygame.draw.rect(window,black,(510,193,260,126),5)
            pygame.draw.rect(window,black,(510,319,260,126),5)
            pygame.draw.circle(window,gray2,(640,550),(40),4)
            pygame.draw.circle(window,gray,(640,550),(35),0)
            window.blit(stimuli_text_to_show, (640 - stimuli_text_to_show.get_width() //2, 205))
            window.blit(answer_text_to_show, (640 - answer_text_to_show.get_width() //2, 331))
            pygame.draw.circle(window,black,(540,120),(40),4)
            window.blit(correct_text, (540 - correct_text.get_width() //2 , 109 ))
            window.blit(dorost_text_to_show, (510, 40 ))
            pygame.draw.circle(window,black,(745,120),(40),4)
            window.blit(uncorrect_text, (745 - uncorrect_text.get_width() //2 , 109 ))
            window.blit(nadorost_text_to_show, (715, 40))
            window.blit(current_time_text, (642 - current_time_text.get_width()//2 , 100 ))
            pygame.draw.rect(window,time_box_color,(607 ,85 ,70,50),time_box_thikness)
            window.blit(shomare_azmoon_to_show, (1100, 20))
            window.blit(key_image,(300,610))
            pygame.draw.rect(window,green,(814 ,650 ,45,35),1)
            pygame.draw.rect(window,red,(308 ,651 ,43,35),1)
            pygame.display.flip()

        if (event.type == pygame.KEYDOWN) :      
            if (event.key == pygame.K_RCTRL) and lctrl_time + 0.01 < time.time()  and rctrl_time + 0.01 < time.time() and i == 0:

                stimuli_counter += 1
                answer_counter += 1
                correct_answer_counter += 1
                i += 1
                if stimuli_counter == 155:
                    stimuli_counter = 0
                    answer_counter = 0
                    correct_answer_counter = 0


                if correct_answer == 1 :

                    correct += 1
                    window.fill(madgray)
                    pygame.draw.rect(window,black,(510,193,260,126),5)
                    pygame.draw.rect(window,black,(510,319,260,126),5)
                    pygame.draw.circle(window,gray2,(640,550),(40),4)
                    pygame.draw.circle(window,alarm_green,(640,550),(35),0)
                    window.blit(stimuli_text_to_show, (640 - stimuli_text_to_show.get_width() //2, 205))
                    window.blit(answer_text_to_show, (640 - answer_text_to_show.get_width() //2, 331))
                    pygame.draw.circle(window,black,(540,120),(40),4)
                    window.blit(correct_text, (540 - correct_text.get_width() //2 , 109 ))
                    window.blit(dorost_text_to_show, (510, 40 ))
                    pygame.draw.circle(window,black,(745,120),(40),4)
                    window.blit(uncorrect_text, (745 - uncorrect_text.get_width() //2 , 109 ))
                    window.blit(nadorost_text_to_show, (715, 40))
                    window.blit(current_time_text, (642 - current_time_text.get_width()//2 , 100 ))
                    pygame.draw.rect(window,time_box_color,(607 ,85 ,70,50),time_box_thikness)
                    window.blit(shomare_azmoon_to_show, (1100, 20))
                    window.blit(key_image,(300,610))
                    pygame.draw.rect(window,green,(814 ,650 ,45,35),2)
                    pygame.draw.rect(window,red,(308 ,651 ,43,35),1)
                    pygame.display.flip()
                    winsound.Beep(freq_correct, duration_correct)
                    time.sleep(0.5)
                    i -= 1
                    rctrl_time = time.time()

                elif correct_answer == 0 :
                    uncorrect += 1
                    window.fill(madgray)
                    pygame.draw.rect(window,black,(510,193,260,126),5)
                    pygame.draw.rect(window,black,(510,319,260,126),5)
                    pygame.draw.circle(window,gray2,(640,550),(40),4)
                    pygame.draw.circle(window,alarm_red,(640,550),(35),0)
                    window.blit(stimuli_text_to_show, (640 - stimuli_text_to_show.get_width() //2, 205))
                    window.blit(answer_text_to_show, (640 - answer_text_to_show.get_width() //2, 331))
                    pygame.draw.circle(window,black,(540,120),(40),4)
                    window.blit(correct_text, (540 - correct_text.get_width() //2 , 109 ))
                    window.blit(dorost_text_to_show, (510, 40 ))
                    pygame.draw.circle(window,black,(745,120),(40),4)
                    window.blit(uncorrect_text, (745 - uncorrect_text.get_width() //2 , 109 ))
                    window.blit(nadorost_text_to_show, (715, 40))
                    window.blit(current_time_text, (642 - current_time_text.get_width()//2 , 100 ))
                    pygame.draw.rect(window,time_box_color,(607 ,85 ,70,50),time_box_thikness)
                    window.blit(shomare_azmoon_to_show, (1100, 20))
                    window.blit(key_image,(300,610))
                    pygame.draw.rect(window,green,(814 ,650 ,45,35),2)
                    pygame.draw.rect(window,red,(308 ,651 ,43,35),1)
                    pygame.display.flip()
                    winsound.Beep(freq_uncorrect, duration_uncorrect)
                    time.sleep(0.5)
                    i -= 1
                    rctrl_time = time.time()

            if (event.key == pygame.K_LCTRL) and rctrl_time + 0.01 < time.time()  and lctrl_time + 0.01 < time.time() and i == 0:



                stimuli_counter += 1
                answer_counter += 1
                correct_answer_counter += 1
                i += 1
                if stimuli_counter == 155:
                    stimuli_counter = 0
                    answer_counter = 0
                    correct_answer_counter = 0

                if correct_answer == 1 :
                    uncorrect += 1

                    window.fill(madgray)
                    pygame.draw.rect(window,black,(510,193,260,126),5)
                    pygame.draw.rect(window,black,(510,319,260,126),5)
                    pygame.draw.circle(window,gray2,(640,550),(40),4)
                    pygame.draw.circle(window,alarm_red,(640,550),(35),0)
                    window.blit(stimuli_text_to_show, (640 - stimuli_text_to_show.get_width() //2, 205))
                    window.blit(answer_text_to_show, (640 - answer_text_to_show.get_width() //2, 331))
                    pygame.draw.circle(window,black,(540,120),(40),4)
                    window.blit(correct_text, (540 - correct_text.get_width() //2 , 109 ))
                    window.blit(dorost_text_to_show, (510, 40 ))
                    pygame.draw.circle(window,black,(745,120),(40),4)
                    window.blit(uncorrect_text, (745 - uncorrect_text.get_width() //2 , 109 ))
                    window.blit(nadorost_text_to_show, (715, 40))
                    window.blit(current_time_text, (642 - current_time_text.get_width()//2 , 100 ))
                    pygame.draw.rect(window,time_box_color,(607 ,85 ,70,50),time_box_thikness)
                    window.blit(shomare_azmoon_to_show, (1100, 20))
                    window.blit(key_image,(300,610))
                    pygame.draw.rect(window,green,(814 ,650 ,45,35),1)
                    pygame.draw.rect(window,red,(308 ,651 ,43,35),2)
                    pygame.display.flip()
                    winsound.Beep(freq_uncorrect, duration_uncorrect)
                    time.sleep(0.5)
                    i -= 1
                    lctrl_time = time.time()

                elif correct_answer == 0 :

                    correct += 1
                    window.fill(madgray)
                    pygame.draw.rect(window,black,(510,193,260,126),5)
                    pygame.draw.rect(window,black,(510,319,260,126),5)
                    pygame.draw.circle(window,gray2,(640,550),(40),4)
                    pygame.draw.circle(window,alarm_green,(640,550),(35),0)
                    window.blit(stimuli_text_to_show, (640 - stimuli_text_to_show.get_width() //2, 205))
                    window.blit(answer_text_to_show, (640 - answer_text_to_show.get_width() //2, 331))
                    pygame.draw.circle(window,black,(540,120),(40),4)
                    window.blit(correct_text, (540 - correct_text.get_width() //2 , 109 ))
                    window.blit(dorost_text_to_show, (510, 40 ))
                    pygame.draw.circle(window,black,(745,120),(40),4)
                    window.blit(uncorrect_text, (745 - uncorrect_text.get_width() //2 , 109 ))
                    window.blit(nadorost_text_to_show, (715, 40))
                    window.blit(current_time_text, (642 - current_time_text.get_width()//2 , 100 ))
                    pygame.draw.rect(window,time_box_color,(607 ,85 ,70,50),time_box_thikness)
                    window.blit(shomare_azmoon_to_show, (1100, 20))
                    window.blit(key_image,(300,610))
                    pygame.draw.rect(window,green,(814 ,650 ,45,35),1)
                    pygame.draw.rect(window,red,(308 ,651 ,43,35),2)
                    pygame.display.flip()
                    winsound.Beep(freq_correct, duration_correct)
                    time.sleep(0.5)
                    i -= 1
                    lctrl_time = time.time()

                total_steps = correct + uncorrect
                output = open ('resuls-{0}.txt'.format(running_number),'w')
                print('Total steps = ', total_steps , 'Correct = ', correct , 'Uncorrect = ', uncorrect ,'Remain time = ',current_time, 'Total time = ', t1 , file = output)

    pygame.quit()              

1 Ответ

0 голосов
/ 11 мая 2018
import pygame
import arabic_reshaper
import time

pygame.init()
window = pygame.display.set_mode((800,600))
pygame.display.set_caption("Stroop Test")

madgray = (110,110,110)
red = (255,0,0)
green =(118,238,0)
black = (0,0,0)
blue = (0,0,255)
white = (255,255,255)

i = 0
stimuli_counter = 0
answer_counter = 0

text_red = u'\u0642\u0631\u0645\u0632' #Red word in Persian (ghermez)
text_blue = u'\u0622\u0628\u0649'
text_green = u'\u0633\u0628\u0632'
text_white = u'\u0633\u0641\u064A\u062F'

r_text_red = arabic_reshaper.reshape(text_red)
r_text_blue = arabic_reshaper.reshape(text_blue)
r_text_green = arabic_reshaper.reshape(text_green)
r_text_white = arabic_reshaper.reshape(text_white)

from bidi.algorithm import get_display
dr_text_red = get_display(r_text_red)
dr_text_blue = get_display(r_text_blue)
dr_text_green = get_display(r_text_green)
dr_text_white = get_display(r_text_white)

first_font = pygame.font.Font('BNazanin_1.ttf',100)

text_red_red = first_font.render(dr_text_red, True,red,madgray)
text_red_blue = first_font.render(dr_text_red, True,blue,madgray) 
text_red_green = first_font.render(dr_text_red, True,green,madgray)
text_red_white = first_font.render(dr_text_red, True,white,madgray)
text_red_black = first_font.render(dr_text_red, True,black,madgray)

text_blue_red = first_font.render(dr_text_blue, True,red,madgray)
text_blue_blue = first_font.render(dr_text_blue, True,blue,madgray)
text_blue_green = first_font.render(dr_text_blue, True,green,madgray)
text_blue_white = first_font.render(dr_text_blue, True,white,madgray)
text_blue_black = first_font.render(dr_text_blue, True,black,madgray)

text_green_red = first_font.render(dr_text_green, True,red,madgray)
text_green_blue = first_font.render(dr_text_green, True,blue,madgray)
text_green_green = first_font.render(dr_text_green, True,green,madgray)
text_green_white = first_font.render(dr_text_green, True,white,madgray)
text_green_black = first_font.render(dr_text_green, True,black,madgray)

text_white_red = first_font.render(dr_text_white, True,red,madgray)
text_white_blue = first_font.render(dr_text_white, True,blue,madgray)
text_white_green = first_font.render(dr_text_white, True,green,madgray)
text_white_white = first_font.render(dr_text_white, True,white,madgray)
text_white_black = first_font.render(dr_text_white, True,black,madgray)

stimuli_lib = [text_red_red, text_red_blue, text_red_green, text_red_white,
                text_blue_red, text_blue_blue,text_blue_green, text_blue_white,
                 text_green_red, text_green_blue, text_green_green, text_green_white,
                  text_white_red, text_white_blue, text_white_green, text_white_white]

answer_lib = [text_red_black, text_blue_black, text_green_black, text_white_black]

stimuli_changer = [2,13,11,9,3,14,8,12,4,1,6,
                   7,2,8,12,6,7,4,14,13]

answer_changer = [1,3,1,0,1,2,3,1,3,2,1,
                  2,1,2,3,1,3,0,2,1]

gameloop = True
while gameloop :

for event in pygame.event.get():

    if (event.type == pygame.QUIT):
            gameloop = False


    if i == 0 :

        stimuli_stage = stimuli_changer[stimuli_counter]
        stimuli_text_to_show = stimuli_lib[stimuli_stage]
        answer_stage = answer_changer[answer_counter]
        answer_text_to_show = answer_lib[answer_stage]

        window.fill(madgray)          
        window.blit(stimuli_text_to_show, (400 , 205))
        window.blit(answer_text_to_show, (400 , 331))
        pygame.display.flip()

    if (event.type == pygame.KEYDOWN) :      
        if (event.key == pygame.K_SPACE) :

            stimuli_counter += 1
            answer_counter += 1

            window.fill(madgray)
            window.blit(stimuli_text_to_show, (400 , 205))
            window.blit(answer_text_to_show, (400 , 331))
            time.sleep(0.5)

            if stimuli_counter == 20:
                gameloop = False

pygame.quit ()

...