2014-07-08 78 views
-5

我正在製作visuall反應時間測試儀和記錄儀。我無法弄清楚這有什麼問題,請幫忙。它引發了ReactionTime未定義的錯誤。再經過你一些其他虛假錯誤修復使用Python的反應時間測試測試儀

#Imports   

import pygame 
import pyHook 
import pythoncom 
import logging 
import sys 
import win32api 
import win32con 
from datetime import datetime 
from datetime import timedelta 
from random import randint 
from math import * 

#Creates PyGame Window 
pygame.init() 

screen = pygame.display.set_mode((640, 480)) 

screen.fill((255, 255, 255)) 

#Starts Counter to Start Reaction Time Start 
a= 0 
for x in range(0, 100): 
    a = a +1 
print(datetime.now()) 

#Starts Reaction Time After Dot Appears 
if a == 100: 
    pygame.draw.circle(screen, (0, 0, 0), (320, 240), 20) 
    ReactionStart= datetime.now() 
    print(ReactionStart) 

#Tells If Someone Pushes A Key And Stops Timer 
def OnKeyboardEvent(event): 
    ReactionEnd == datetime.now() 
    print (ReactionEnd) 

#Makes Sure That The Program Knows a Key was pressed 
hooks_manager = pyHook.HookManager() 
hooks_manager.KeyDown = OnKeyboardEvent 
hooks_manager.HookKeyboard() 
pythoncom.PumpMessages() 

#Calculates Reaction Time 
ReactionTime == ReactionEnd - ReactionStart 
print (ReactionTime) 


#Unknown 
pygame.display.flip() 

#Makes Sure You Can exit The Test 
while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
+0

不是調試服務... – dawg

+0

您甚至沒有添加(完整)錯誤消息。 – furas

+0

'=='與'=' – bsoist

回答

1

您正在使用兩種==地方,你幾乎可以肯定,試圖分配一個值的問題。你應該使用=

0

bsois找到解決方案 - 我只顯示沒有所有模塊的代碼。

import pygame 
from datetime import datetime 
import time 

pygame.init() 
screen = pygame.display.set_mode((640, 480)) 

#---- 

for x in range(5): # repeat 5 times 

    screen.fill((255, 255, 255)) 

    # Send `screen` on monitor - show white screen 
    pygame.display.flip() 

    # wait 3 seconds 
    time.sleep(3) 

    pygame.draw.circle(screen, (0, 0, 0), (320, 240), 20) 

    # Send `screen` on monitor - show circle 
    pygame.display.flip() 

    reaction_start = datetime.now() 

    # wait for key press 
    running = True 
    while running: 
     for event in pygame.event.get(): 
      if event.type == pygame.KEYDOWN: 
       reaction_end = datetime.now() 
       running = False 

    # result 
    print(reaction_start) 
    print(reaction_end) 
    print(reaction_end - reaction_start) 

#---- 

# clear `screen` 
screen.fill((255, 255, 255)) 

# create font 
font = pygame.font.SysFont(None, 30) 

# create green text 
text = font.render("PRESS ANY KEY TO EXIT", 0, (0,255,0)) 

# get text (rectangle) size and move to center of screen 
text_rect = text.get_rect(center=screen.get_rect().center) 

# put text on `screen` 
screen.blit(text, text_rect) 

# send `screen` on monitor 
pygame.display.flip() 

# wait for key to close program 
while True: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
     if event.type == pygame.KEYDOWN: 
      pygame.quit() 
+0

非常感謝你的幫助 – user3814609

+0

有沒有什麼原因讓這個重複x次? – user3814609

+0

使用'for'循環。 – furas