库未在Python中初始化(pygame) [英] Library not initialized in Python (pygame)
问题描述
所以我有在类函数中创建的字体.我在代码中多次调用了此函数,并且效果很好,但是一次调用它时却说:
so I have a font that I create in a class function. I called this function many times in the code and it works perfectly, but one time when I call it it says:
self.font = pygame.font.Font( None, self.text_size )
RuntimeError: Library not initialized
我无法修复它!所以在 self.font 行之前的一行我做了 pygame.init()
I couldn't fix it! so a line before the self.font line I did pygame.init()
还是一样..WTF
请帮助,谢谢.
推荐答案
好的,我修复了它.
该行:
self.font = pygame.font.Font( None, self.text_size )
在新线程中,因此无法识别库
Was in a new Thread, therefore the libraries wasn't recognized
所以我得到了字体,并在 __ init __ 函数中创建了标签,并将其作为自己.之后,我可以毫无问题地在Thread中使用它们,因为我采用了字体-将其作为表面( Font.render )并使用了.
So I got the font and made the label in the __init__ function and made them as self. after that I could use them in the Thread without a problem, because I took the font - made it as a surface (Font.render) and used.
这篇关于库未在Python中初始化(pygame)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!