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

Python Ursina引擎如何调整WindowPanel窗口面板的生成显示位置?

Ursina引擎WindowPanel位置调整方法

直接给WindowPanel实例添加position参数即可控制其屏幕显示位置,Ursina UI采用归一化屏幕坐标:

  • x轴取值范围:-0.5(屏幕最左侧)~ 0.5(屏幕最右侧)
  • y轴取值范围:-0.5(屏幕最下方)~ 0.5(屏幕最上方)

默认锚点为WindowPanel的中心,你可以根据需求调整坐标数值,修改后的示例代码如下:

from ursina import *

app = Ursina()

test = InputField(text='')

UI = WindowPanel(
    title='Menu',
    content=(
        Text('Username:'),
        test,
        Button(text='Submit', color=color.azure),
        Button(text='Free Play'),
        Button(text='Challenge'),
        Button(text='Leaderboard')
        ),
        popup=True,
        enabled=True,
        position = (-0.3, 0.3) # 示例坐标,可自行调整数值修改位置
    )

# 如需对齐屏幕边角,可搭配origin参数修改锚点
# 例:将锚点设为WindowPanel左上角,再赋值position为(-0.5, 0.5)即可完全对齐屏幕左上角
# UI.origin = (-0.5, 0.5)
# UI.position = (-0.5, 0.5)

app.run()

补充说明

  • 运行过程中需要动态修改位置时,直接对UI.position赋值即可实时生效
  • popup=True的弹出动画不会修改最终停留的position参数,无需额外处理动画干扰

内容的提问来源于stack exchange,提问作者Gage Fulwood

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 08:54:04