Python“调用draw()时必须使用Label instance作为第一个参数(改为get\u WindowMetaclass instance)”

2024-06-15 07:51:05 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我用Python和pyglet创建的一个类来显示窗口。在

class Window(pyglet.window.Window):
    def __init__(self):
        super(Window, self).__init__()

        pyglet.text.Label("Prototype")

        windowText = text.Label.draw(Window, "Hello World",
                          font_name = "Times New Roman",
                          font_size = 36,
                          color = (193, 205, 193, 255))

    def on_draw(self):
        self.clear()
        self.label.draw()

每次我尝试运行它时,都会出现错误“TypeError:unbound method draw()必须以Label instance作为第一个参数进行调用(改为get\u WindowMetaclass instance)”。我很确定我知道我要做什么(找到如何获得Label的实例),只是不知道如何去做。有人能帮我弄明白怎么做这个吗?在


Tags: instancetextselfinitdefwindowlabelclass
2条回答

如果我不得不猜测,我会说你应该绑定你在上面创建的两行实例,然后使用它。在

    mylabel = pyglet.text.Label("Prototype")

    windowText = mylabel.draw(...

你给一个类“Window”而不是一个实例作为参数,试试“self”

相关问题 更多 >