Pygame window not responding, but program continues to run

对着背影说爱祢 提交于 2020-04-16 07:42:01

问题


I am an enthusiast fairly new to working with 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. 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. I am using Pycharm with python 3.8.1 and Pygame version 1.9.6 installed. I am using a Mac with High Sierra.

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.

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


回答1:


pygame 1.9.6 does not work with python 3.8.1 on mac os.

See https://github.com/pygame/pygame/issues/555 for details.

Try installing a pygame development version such as pygame 2.0.0.dev6:

pip3 install pygame==2.0.0.dev6

But watch out for bugs.



来源:https://stackoverflow.com/questions/59939813/pygame-window-not-responding-but-program-continues-to-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!