【问题标题】:Pygame window not responding, but program continues to runPygame 窗口没有响应,但程序继续运行
【发布时间】:2020-01-27 22:28:53
【问题描述】:

我是一个对 python 工作相当陌生的爱好者。我安装 Pygame 已经一周了,经过多次尝试,当我运行任何程序时,仍然无法启动或打开 Pygame 窗口。我已经尽可能多地观看了教程,并阅读了所有关于我能找到的类似问题的文章。我已经复制了在其他网站上找到的所有解决方案,但问题仍然存在。尽管如此,奇怪的是,我使用的 IDE (Pycharm) 很少输出错误消息,而是继续运行但从不启动 Pygame 窗口。我正在使用安装了 python 3.8.1 和 Pygame 版本 1.9.6 的 Pycharm。我正在使用带有 High Sierra 的 Mac。

我非常感谢任何人可以提供的任何帮助。

以下代码仅输出 pygame 版本和“欢迎”消息,但在没有启动窗口的情况下继续运行。

import pygame

    (width, height) = (1000, 700)
    screen=pygame.display.set_mode((width, height))
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

下一个代码块的输出与上面的完全相同。

    # courtesy of Ene Uran www.daniweb.com

import pygame as pg

pg.init()

screen = pg.display.set_mode((400, 300))

pg.display.set_caption('Draw/fill rectangles using pygame')

white = 0xFFFFFF
red = 0xFF0000
green = 0x00FF00
blue = 0x0000FF
yellow = 0xFFFF00

screen.fill(white, (250, 50, 77, 33))

screen.fill(red, (30, 20, 70, 120))
screen.fill(red, (140, 70, 90, 80))
screen.fill(green, (150, 80, 70, 60))
screen.fill(yellow, (200, 170, 150, 60))
screen.fill(blue, (70, 200, 100, 70))

pg.display.update()


while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            raise SystemExit

以下代码块也返回相同的输出:

import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 24)
#clock = pygame.time.Clock()

#font = pygame.font.Font(None, 32)

cycles = 0
while True:
    pygame.event.get()
    screen.fill(0)
#    text = font.render('Cycles : %d' % cycles, True, (255, 255, 255))
#    screen.blit(text, (100, 100))

    cycles += 1

    pygame.display.update()

此代码^^来自此问题的原始堆栈溢出论坛:Pygame window not responding after a few seconds

【问题讨论】:

  • 在不使用 PyCharm 的情况下运行会获得更好的结果吗?
  • 所有示例在 Windows 10 上的 Python 3.6 x64、Pygame 1.9.6、Pycharm 2019.3 中看起来都很好
  • 不——信不信由你,到目前为止,我无法让 Pygame 导入到 Pycharm 以外的任何 IDE 中。
  • 听起来您需要较早版本的 python 和 pygame。 github.com/pygame/pygame/issues/1554
  • @tgikal - 太棒了!有效。非常感谢您的帮助。

标签: python pygame pycharm


【解决方案1】:

pygame 1.9.6 不适用于 mac 操作系统上的 python 3.8.1

详情请见https://github.com/pygame/pygame/issues/555

尝试安装pygame 2.0.0.dev6等pygame开发版本:

pip3 install pygame==2.0.0.dev6

但要注意错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-08
    相关资源
    最近更新 更多