这是我正在编写的一个程序,它应该在窗口中显示一些文本......
import pyglet
from pyglet import window
from pyglet.text.layout import TextLayout
class Window(pyglet.window.Window):
def __init__(self):
super(Window, self).__init__(width = 800, height = 600,
caption = "Prototype")
self.disclaimer = pyglet.text.Label("Hello World",
font_name = 'Times New Roman',
font_size=36,
color = (255, 255, 255, 255),
x = TextLayout.width / 2,
y = TextLayout.height / 2,
anchor_x='center', anchor_y='center')
def on_draw(self):
self.clear()
self.disclaimer.draw()
if __name__ == '__main__':
window = Window()
pyglet.app.run()
...但是每次我尝试运行它时,我都会收到此错误
line 16
x = TextLayout.width / 2,
TypeError: unsupported operand type(s) for /: 'property' and 'int'
我很确定这意味着我试图分割一个字符串,但在 Pyglet 文档中它说宽度和高度是整数。我不知道我做错了什么。