以下是从一本书上抄下来稍加改动的源代码,在 Python Idle 里运行没有报错,然而弹出的 pygame 窗口却除了显示窗口标题外一片漆黑
import pygame
import sys
# set everything to where started
pygame.init()
size = width, height = 650, 650
speed = [-2,1]
bg = (255, 255, 255)
# create a window with a determined size
screen = pygame.display.set_mode(size)
# create window title
pygame.display.set_caption("Hello!")
ball = pygame.image.load("D://Python//soccer.jpg")
# position of the image
position = ball.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# move the image
position = position.move(speed)
if position.left < 0 or position.right > height:
# flip image
turtle = pygame.transform.flip(ball, True, False)
# move to the other side
speed[1] = -speed[1]
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
# fill the background
screen.fill()
# refresh image
screen.blit(ball, position)
# refresh screen
pygame.display.flip()
pygame.display.update()
# 10ms delay
pygame.time.delay(10)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。