envface1=pygame.image.load(p1)
envface2=pygame.image.load(p2)
envface1=pygame.transform.scale(envface1,(768,400))
envface2=pygame.transform.scale(envface2,(768,400))
start = timeit.default_timer()
window.blit(txt[0],(0,0))
window.blit(envface1,(0,400))
window.blit(envface2,(800,400))
pygame.display.flip()
display=False
while not display:
#delete the print will make it no responding
print
keys=pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
display=True
print "1"
if keys[pygame.K_RIGHT]:
display=True
print "2"
end=timeit.default_timer()
print end-start
pygame.quit()
对于代码的这一部分,我试图让用户可以选择他们喜欢的图片并打印出结果。但是在while循环中,当我删除只带有“print”的行并运行它时,程序将关闭并使它没有响应。为什么会这样
正如赛博所解释的,您有一个while循环,它在
display
为false时运行。但是,由于在循环中根本不修改display
,因此实际上创建了一个无限循环你观察到程序不会响应是因为在无限循环中没有任何事情发生,除非按下一个键
相关问题 更多 >
编程相关推荐