"TypeError: draw() takes exactly 1 non-keyword argument (3 given)"
I wrote this code to open a 开发者_JAVA百科window with Pyglet in Python...
import pyglet
from pyglet import window
class Window(pyglet.window.Window):
def __init__(self):
super(Window, self).__init__()
myLabel = pyglet.text.Label("Prototype")
windowText = myLabel.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()
if __name__ == '__main__':
window = Window()
pyglet.app.run()
however every time I run it I get this error:
TypeError: draw() takes exactly 1 non-keyword argument (3 given)
AFAIK the "(3 given)" means the problem is with the font_size or color arguments but I'm not sure. Could someone explain what's wrong and help me make this work?
The three non-keyword arguments you've given are the object instance, Window
, and "Hello World"
. It only expects the object instance. Check the docs again for which arguments the draw()
method takes. Consider printing the repr()
of myLabel
so that you know which type it is.
The three non-keyword arguments you're passing to draw() are myLabel (implied, becomes self
), Window, and "Hello World". The documentation for this method is here.
Are you sure you didn't intend to do something more like this?
myLabel = pyglet.text.Label("Hello World")
I've never used pyglet but according to the documentation draw does not take any parameters.
However the constructor does take these parameters so the following would be legal:
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=10, y=10)
From here.
精彩评论