开发者

Python "draw() must be called with Label instance as first argument (got _WindowMetaclass instance instead)"

开发者 https://www.devze.com 2023-01-03 18:59 出处:网络
This is a class I made using Python with pyglet to开发者_高级运维 display a window. class Window(pyglet.window.Window):

This is a class I made using Python with pyglet to开发者_高级运维 display a window.

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()

Every time I try to run it I get the error "TypeError: unbound method draw() must be called with Label instance as first argument (got _WindowMetaclass instance instead)". I'm pretty sure I know what I have to do (find how to get Label's instance) just not how to do it. Could someone help me understand how to make this work?


If I had to guess, I'd say that you should bind the instance you create 2 lines above and use that instead.

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

    windowText = mylabel.draw(...


you give a class "Window" instead of an instance as argument, try "self"

0

精彩评论

暂无评论...
验证码 换一张
取 消