[问题] MacOS Python3 IDLE 执行 pygame code

楼主: iwaitforyou (小烂)   2020-03-09 16:13:51
请教,
MacOS 用 Python IDLE 执行 pygame code 后,
他有持续在跑,Python Launcher 有在动,
可是就是不会出现视窗...
如图:
https://imgur.com/pha4W48
程式码:
import pygame
import sys
import os
os.chdir("路径")
pygame.init() #初始化 Pygame
size = width, height = 600, 400
speed = [-2, 1]
bg = (255, 255, 255)
screen = pygame.display.set_mode(size) #创建指定大小的窗口
pygame.display.set_caption("初次见面,请大家多多关照!") #设置窗口标题
turtle = pygame.image.load("turtle.png")
position = turtle.get_rect() #获得图像的位置矩形
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
position = position.move(speed) #移动图像
if position.left < 0 or position.right > width:
turtle = pygame.transform.flip(turtle, True, False) #翻转图像
speed[0] = -speed[0] #反方向移动
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
screen.fill(bg) #填充背景
screen.blit(turtle, position) #更新图像
pygame.display.flip() #更新接口
pygame.time.delay(10) #延迟 10 毫秒

Links booklink

Contact Us: admin [ a t ] ucptt.com