niceyes 发表于 2021-8-16 17:54:04

大师门帮看看,无法退出 pygame 游戏窗体!!!

clock=pygame.time.Clock()
while True:                                       
    clock.tick(60)                                    # 使用时钟对象的方法,设定停顿时间:1/参数,也即 帧率
    for event in pygame.event.get():         # event.get() 获取用户操作返回列表,遍历它
   
      if event.type==pygame.QUIT:
            pygame.quit()               # unload pygame 模块
            sys.exit()                        # 退出程序

    #修改飞机位置:
    if hero_rect.y<=-126:         #当飞机飞出屏幕,就调整飞机的位置
      hero_rect.y=700
    hero_rect.y-=1

    screen.blit(img_bg, (0, 0))                      #重画背景
    screen.blit(hero,hero_rect)                      #重画飞机
    pygame.display.update()


点游戏右上角的叉 ,无法退出游戏窗体,            控制台显示有 [<Event(32787-WindowClose {'window': None})>, <Event(256-Quit {})>]

nahongyan1997 发表于 2021-8-16 18:24:17

idle 跟 pygame 有冲突的,你直接双击打开的话就不会了

Pliosauroidea 发表于 2021-8-16 19:35:16

?我补全后在pycharm里跑了一下,发现可以正常退出
import pygame
import sys

clock = pygame.time.Clock()
pygame.init()
(screen_width, screen_height) = (800, 600)
screen = pygame.display.set_mode((screen_width, screen_height))
while True:
    clock.tick(60)# 使用时钟对象的方法,设定停顿时间:1/参数,也即 帧率
    for event in pygame.event.get():# event.get() 获取用户操作返回列表,遍历它

      if event.type == pygame.QUIT:
            pygame.quit()# unload pygame 模块
            sys.exit()# 退出程序

    # 修改飞机位置:
    pass

    pygame.display.update()

叼辣条闯世界 发表于 2021-8-16 20:44:35

IDLE 跟 pygame 冲突
双击打开

niceyes 发表于 2021-8-20 01:19:07

多谢 大家
页: [1]
查看完整版本: 大师门帮看看,无法退出 pygame 游戏窗体!!!