[問題] MacOS Python3 IDLE 執行 pygame code

看板Python作者 (小爛)時間4年前 (2020/03/09 16:13), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
請教, 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 毫秒 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.195.160.41 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1583741633.A.21C.html
文章代碼(AID): #1UPVh18S (Python)