import pygame import sys from pygame.locals import * # wait for keys to putdown def waitForKeys(keysAllowed): key = False # initialize the key pygame.event.clear() # clear the event while not key: for i in pygame.event.get(): # for every event in the event list if i.type == pygame.KEYDOWN or i.type == pygame.KEYUP: # if the event type is keydown if i.key inkeysAllowed: # IF IS at The Key Special Key # If if i.key == K_0 or K_1 or K_2 , then press any key will quit because of logic or become (if i.key == K_0) or K_1 this form Print (i.key, pygame.key.name (i.key)) Key = True # BREAK the while Loop The return 0 # reture The value # Draw A TWO Sentences DEF displayOneQuestion (myString): pygame.init () # the initialize pygame mywin pygame.display.set_mode = ((800, 600), DOUBLEBUF | HWSURFACE) # the Create at The window myFont = pygame.font.SysFont ( " Chinese Song ", 25,False, False) # create the font myStringSurface = myFont.render(myString, True, (255,255,255), False) # create the string myString1 = "1 有点 2 中等 3 很多" myStringSurface1 = myFont.render(myString1, True, (255,255,255), None) mywin.blit(myStringSurface, (1,1), None, 0) # draw the font surface to another surface mywin.blit(myStringSurface1, (1,100), None, 0) # draw another surface pygame.display.flip() # flip the window return 0 # return 0 myString = [" Hello " , " I can not " , " eat it " , " dry well Zhe City " , " Not yet " , " Okay " ] keysAllowed = [pygame.K_1, pygame.K_2, pygame.K_3, pygame.K_4, pygame.K_5] for Element in myString: displayOneQuestion (Element) waitForKeys (keysAllowed) # Note 1 point: If pygame.event.clear () # clear the event on this one while: the beginning, the program will very slow, and some will skip, I do not know why. # Note Point 2: If if i.key == K_0 or K_1 or K_2, then press any key will quit because of logic or become (if i.key == K_0) or K_1 this form, and if i.key == (K_0 or K_1) is not acceptable.
This is a questionnaire interface problems (of course, the problem is I made it up, and not very beautiful, the latter can be adjusted)
Keys need to be tested to see next question, press the keys include 1,2,3,4,5
This is the interface to the second question
This is the result of the completion of five questions, I printed out the value of the ASC button, and the name of the key, you can see the name of the digital keys on the keyboard.
Summary: The problem of the interface, where the problem is, the content of the answer, the answer position can be set, since the content did not get the questionnaire now, so the questionnaire is Xia Xie. The main advantage of using pygame is skipped written tests, and test reaction may be (key) into the database.