You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Ursina框架创建TextureBox时出现AttributeError错误求助

问题描述

运行基于Ursina框架的Python代码时出现AttributeError,尝试IDE快速修复后问题仍未解决,具体报错及代码如下:

报错信息

:prc(warning): Invalid integer value for ConfigVariable win-size: 864.0
:prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0
Known pipe types:
  wglGraphicsPipe
(3 aux display modules not yet loaded.)
:prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'.
:pnmimage:png(warning): iCCP: known incorrect sRGB profile
Traceback (most recent call last):
  File "C:\Users\LENOVO\PycharmProjects\pythonProject\main.py", line 37, in <module>
    TextureBox()
  File "C:\Users\LENOVO\PycharmProjects\pythonProject\main.py", line 18, in __init__
    super().__innit(
    ^^^^^^^^^^^^^^^
AttributeError: 'super' object has no attribute '_TextureBox__innit'

Process finished with exit code 1

相关代码

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController

app = Ursina()
for z in range(10):
    for x in range(10):
        Entity(
            model="cube", color=color.dark_gray, collider="box", ignore=True,
            position=(x, 0, z),
            parent=scene,
            origin_y=0.5,
            text="white_cube"
        )


class TextureBox(Button):
    def __init__(self, position=(5, 2, 5)):
        super().__innit(
            parent=scene,
            position=position,
            model="cube",
            origin_y=0.5,
            texture="texture.jpg",
            color=color.color(0, 0, 1)
        )
        self.texture_choice = 0
        self.textures = ["texture.jpg", "wood.jpg", "stones.jpg", "blue.jpg"]

    def input(self, key):
        if self.hovered:
            if key == 'left mouse down':
                self.texture_choice += 1
                self.texture_choice %= len(self.textures)
                self.texture = self.textures[self.texture_choice]


TextureBox()
player = FirstPersonController()

解决方案

  • 核心错误修复:报错的直接原因是拼写错误——将父类初始化方法__init__误写为__innit__(多了一个n)。把super().__innit(修改为super().__init(即可解决AttributeError。
  • 其他警告处理(可选):
    • win-size警告:Ursina要求窗口尺寸为整数,当前传入了浮点数,可在初始化时指定整数尺寸,比如app = Ursina(window_size=(864, 1536))
    • iCCP警告:属于PNG图片的sRGB配置文件兼容问题,可忽略该警告,或用图片编辑工具重新导出图片去除该配置

内容的提问来源于stack exchange,提问作者Quilly The Legend

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 01:45:31