否则pygame不会变色

否则pygame不会变色

本文介绍了除非我调用pygame.event.get(),否则pygame不会变色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我的头撞到显示器上两个小时后,我意识到:

After crashing my head against the monitor for 2 hours I realised that:

display.blit(mypic, posx, posy)
pygame.display.update()

除非我打电话给我,否则

就是行不通的(即不会在屏幕上显示任何内容).

would just not work (i.e. wouldn't blit anything on the screen) unless I call:

pygame.event.get()

这是地球上最怪异的虫子,还是我错过了什么?

Is this the weirdest bug on earth, or am I missing something?

我正在python 2.7上运行pygame,mac os high sierra,是的,如果这是由于pygame和mac os之间的不兼容,那么我将最不惊讶.

I'm running pygame on python 2.7, mac os high sierra,and yes I would be the least surprised if this was due to the goddam incompatibility between pygame and mac os.

关于这里出了什么问题的任何提示吗?

示例代码:

import pygame
winWidth = 800
winHeight = 600
posx = 200; posy = 200
mypic = pygame.image.load("path_to_my_picture.jpg")
COL_BACKGROUND = (255,255,255)

DISPLAYSURF = pygame.display.set_mode((winWidth, winHeight))
pygame.init()
display.fill(COL_BACKGROUND)
display.blit(mypic, posx, posy)

# only including the following line it will blit the picture:
# pygame.event.get()

pygame.display.update()

推荐答案

我不确定100%是否与mac兼容,但是我假设它与Windows相似,如果您不定期调用pygame.event.get()操作系统认为该窗口已停止响应,并且不再更新它.

I'm not 100% sure how it works with mac but I am assuming it is similar to windows in that if you don't call pygame.event.get() regularly the operating system thinks that the window has stopped responding and no longer updates it.

pygame.event.pump()下提及在Pygame文档的事件页面中

This is mentioned under pygame.event.pump() in the events page of the Pygame documentation

这篇关于除非我调用pygame.event.get(),否则pygame不会变色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:50