AttributeError: 'str' object has no attribute '_own_batch'
AttributeError: 'str' object has no attribute '_own_batch'
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label.draw("Hello world application")
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
错误:
2021-10-19 13:39:19.070 Python[87264:4558537] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be writ
ten to /var/folders/m9/g3kwd6vn1cx4n7v76ttysp8m0000gn/T/org.python.python.savedState
Traceback (most recent call last):
File "/Users/damanbirsingh/Desktop/alarm.py", line 5, in <module>
label = pyglet.text.Label.draw("Hello world application")
File "/opt/homebrew/lib/python3.9/site-packages/pyglet/text/layout.py", line 1209, in draw
if self._own_batch:
AttributeError: 'str' object has no attribute '_own_batch'
也许你的代码有问题试试下面的代码
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
font_size=36,
x=window.width//2, y=window.height//2)
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
有关详细信息,请访问 https://pyglet.readthedocs.io/en/latest/
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label.draw("Hello world application")
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
错误:
2021-10-19 13:39:19.070 Python[87264:4558537] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be writ
ten to /var/folders/m9/g3kwd6vn1cx4n7v76ttysp8m0000gn/T/org.python.python.savedState
Traceback (most recent call last):
File "/Users/damanbirsingh/Desktop/alarm.py", line 5, in <module>
label = pyglet.text.Label.draw("Hello world application")
File "/opt/homebrew/lib/python3.9/site-packages/pyglet/text/layout.py", line 1209, in draw
if self._own_batch:
AttributeError: 'str' object has no attribute '_own_batch'
也许你的代码有问题试试下面的代码
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
font_size=36,
x=window.width//2, y=window.height//2)
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()
有关详细信息,请访问 https://pyglet.readthedocs.io/en/latest/