简体   繁体   English

Pygame 窗口没有响应,但程序继续运行

[英]Pygame window not responding, but program continues to run

I am an enthusiast fairly new to working with python.我是一个相当新的爱好者,对使用 python 工作。 It has been a week since I installed Pygame, and after numerous attempts, I still can't get the Pygame window to launch or open when I run any of my programs.我安装 Pygame 已经一周了,经过多次尝试,我仍然无法在运行任何程序时启动或打开 Pygame 窗口。 I have watched as many tutorials as I can, as well as reading all the articles on similar issues I could find.我尽可能多地观看了教程,并阅读了我能找到的有关类似问题的所有文章。 I have copied all of the solutions I found on other websites and the problem still persists.我已经复制了我在其他网站上找到的所有解决方案,但问题仍然存在。 Stranger nonetheless, is the fact that the IDE I am using (Pycharm) rarely outputs an error message, and instead simply continues running but never launches the Pygame window.尽管如此,更奇怪的是,我使用的 IDE (Pycharm) 很少输出错误消息,而是继续运行但从不启动 Pygame 窗口。 I am using Pycharm with python 3.8.1 and Pygame version 1.9.6 installed.我正在使用安装了 python 3.8.1 和 Pygame 版本 1.9.6 的 Pycharm。 I am using a Mac with High Sierra.我正在使用带有 High Sierra 的 Mac。

I greatly appreciate any help anyone can provide.我非常感谢任何人可以提供的任何帮助。

The below code only outputs the pygame version and the "welcome" message, but continues to run without the window ever launching.下面的代码仅输出 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()

The next code block has the exact same output as the one above.下一个代码块的输出与上面的完全相同。

    # 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

The following code block also returns the same output:以下代码块也返回相同的输出:

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()

This code^^ is from the original stack overflow forum for this issue: Pygame window not responding after a few seconds此代码^^ 来自此问题的原始堆栈溢出论坛: Pygame window 在几秒钟后没有响应

pygame 1.9.6 does not work with python 3.8.1 on mac os. pygame 1.9.6不适用于 Mac 操作系统上的python 3.8.1

See https://github.com/pygame/pygame/issues/555 for details.有关详细信息,请参阅https://github.com/pygame/pygame/issues/555

Try installing a pygame development version such as pygame 2.0.0.dev6:尝试安装 pygame 开发版本,例如 pygame 2.0.0.dev6:

pip3 install pygame==2.0.0.dev6

But watch out for bugs.但要注意错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM