【发布时间】:2015-10-07 22:54:34
【问题描述】:
这是我的脚本:
import pygame
pygame.init()
gameDisplay = pygame.display.set_mode((600,600))
pygame.display.set_caption('Doge Adventures')
gameexit = False
move_x = 300
move_y = 300
move_x_change = 0
move_y_change = 0
while not gameexit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameexit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
move_x_change = -10
if event.key == pygame.K_RIGHT:
move_y_change = 10
move_x += move_x_change
gameDisplay.fill(white)
pygame.draw.rect(gameDisplay, black, [move_x, move_y, 10, 10])
pygame.display.update()
pygame.quit()
quit()
问题是当我运行它时,什么都没有发生,也没有错误。只是弹出空闲,但没有窗口。我想知道我的代码是否有问题。我正在使用 pygame 2.6 运行 python 2.6
【问题讨论】:
-
您提供的代码格式是否与您的文本编辑器中的格式完全相同?如果是这样,那么您必须缩进所有内容(最后两行除外),以便它们在 while 循环内。
-
完全正确您是如何尝试运行文件的?另外,最后删除“quit()”。如果可能,请升级到 2.7.10 或 3.4 或 3.5。在 5 年多的时间里,许多错误已得到修复,并取得了许多改进。
标签: python pygame python-idle