Python/Pygame : "pygame.error: display Surface quit"

Python/Pygame : "pygame.error: display Surface quit"

所以,我正在制作一个游戏项目,我决定,这一次,为我的 pygame window 定制一个 class,就像这样:

class Screen(pygame.Surface):
    """Class for making a screen"""

    def __init__(self, width: int, height: int):
        """Screen Class Constructor"""
        self = pygame.display.set_mode((width, height))


    def _events(self):
        """Events Handler"""

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

    def _fill(self, color):
        self.fill(color)

并且,在游戏循环中,我决定制作一个 class 的实例,并调用

._fill()

方法,像这样:

# Importing
import pygame
import ScreenClass
import StaticsClass # Class with multiple colors

# Functions
def main():
    """Main function, where all the game happens.."""
    scr = ScreenClass.Screen(800, 600)
    print(type(scr))

    while True:
        scr._fill(StaticsClass.Color.BLACK0)
        scr._events()

if __name__ == '__main__':
    main()

但是当我尝试 运行 主循环时,它给了我这个错误消息(我以前从未见过):

Traceback (most recent call last):
  File "C:\Users\PC\Desktop\PYTHON\Jeux\A While Ago\mainloop.py", line 17, in <module>
    main()
  File "C:\Users\PC\Desktop\PYTHON\Jeux\A While Ago\mainloop.py", line 13, in main
    scr._fill(StaticsClass.Color.BLACK0)
  File "C:\Users\PC\Desktop\PYTHON\Jeux\A While Ago\ScreenClass.py", line 22, in _fill
    self.fill(color)
pygame.error: display Surface quit

而且,也许除了特定行:

self = pygame.display.set_mode((width, height))

我真的不知道为什么会这样。可能是因为无法制作自定义屏幕 class ?

所以我的问题是:为什么会这样?如果我可以自定义 window class,怎么样?因为好像不行...

非常欢迎任何帮助!

编辑 1:如果您需要所有文件的代码,我会让它们可见 :D

尝试初始化父级 class。在你的初始化函数中。

def __init__(self, width: int, height: int):
    """Screen Class Constructor"""
    super().__init__((width, height))
    self = pygame.display.set_mode((width, height))