所以我试图使用 pygame 在屏幕上显示文本。但是,在使用 pyzo 执行第三次或第四次执行后,它可以工作,内核刚刚退出,我必须再次重新启动它。这是相当不稳定和烦人的。
我想知道我可能忘记了什么或做错了什么。我感谢任何花时间研究这个问题的人。
编辑 :
错误是: 内核进程退出。(3221225477)
running = True
while running :
# completely fill the surface object
# with black color
display_surface.fill(black)
# copying the text surface object
# to the display surface object
# at the center coordinate.
update_text_screen(text_to_display)
# iterate over the list of Event objects
# that was returned by pygame.event.get() method.
for event in pygame.event.get() :
if event.type == pygame.QUIT:
running = False
pygame.display.update()
pygame.display.quit()
pygame.quit()
class text:
def __init__(self, message, colour, state, X, Y) :
global text_to_display
self.text_to_print = font_text.render(message, True, colour)
self.X = X
self.Y = Y
self.state = state
def v(self):
display_surface.blit(self.text_to_print,[self.X,self.Y])
def update_text_screen(list_of_text):
global C_px, C_py
for i in range(len(list_of_text)) :
if list_of_text[i].state:
C_py = i*30
list_of_text[i].X = C_px
list_of_text[i].Y = C_py
list_of_text[i].v()
Edit2:这是 Valentino 询问的代码