与孩子一起学编程16章
今天,要用到一个python module了,网上google pygame,选择合适的版本安装。然后在交互模式中检查
,文件名要和代码里一致。import pygame, syspygame.init()screen = pygame.display.set_mode([640, 480])screen.fill([255,255,255])my_ball = pygame.image.load("beach_ball.png")x = 50y = 50x_speed = 5while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() pygame.time.delay(20) pygame.draw.rect(screen, [255,255,255], [x, y, 90, 90], 0) x = x + x_speed if x > screen.get_width(): x = 0 screen.blit(my_ball, [x, y]) pygame.display.flip()还有其他动作,你都可以试试,修改代码,让它跳舞吧!