gpt4 book ai didi

python - 如何修复 '' AttributeError : module 'pyglet.text' has no attribute 'label' "error in python

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:07 25 4
gpt4 key购买 nike

我正在尝试使用 pyglet 创建一个简单的游戏。我仍在学习这个库,并且正在使用 pyglet 编程指南来学习。但是,我得到了

AttributeError: module 'pyglet.text' has no attribute 'label'

每次运行代码都会出错。

我试过import pyglet.textimport pyglet.text.labelimport pyglet.text 仍然给出

AttributeError: module 'pyglet.text' has no attribute 'label'.

但是,import pyglet.text.label 给出

ModuleNotFoundError: No module named 'pyglet.text.label'.

我的代码是:

import pyglet
import pyglet.text.label

window = pyglet.window.Window()
label = pyglet.text.label('Hello World',
font_name='Times New Roman',
font_size=36,
x=window.width//2,
y=window.height//2,
anchor_x='center',
anchor_y='center')
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()

我希望看到窗口被清除为默认背景颜色,屏幕上打印出 Hello World。但我总是得到一个空白窗口

AttributeError: module 'pyglet.text' has no attribute 'label'

打印在 shell 中。

最佳答案

AttributeError: module 'pyglet.text' has no attribute 'label'

您收到此错误是因为您使用的是 pyglet.text.label 而不是 pyglet.text.Label

这是 text 的文档

只导入 pyglet 然后将标签更改为标签,它应该可以工作。

关于python - 如何修复 '' AttributeError : module 'pyglet.text' has no attribute 'label' "error in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55884792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com