简体   繁体   English

更新 Ursina 中的文本实体,Python

[英]Update Text Entity in Ursina, Python

I have this code:我有这段代码:

BUTTON_INDENT = -1

class TIME(Text):

    def __init__(self):

        super().__init__(

             text=time.strftime("%H:%M"),
             position=(0,0,BUTTON_INDENT),

             )

How do I make it so the text inside changes?我该怎么做才能让里面的文字发生变化?

I have tried this before too:我以前也试过这个:

BUTTON_INDENT = -1

class TIME(Text):
    
   def __init__(self):

      super().__init__(

          text=time.strftime("%H:%M"),
          position=(0,0,BUTTON_INDENT)

          )

   def update(self):

      self.text = time.strftime("%H:%M")

That doesn't seem to make the text change either.这似乎也不会改变文本。

Anyhow, the update function doesn't work in Text class, here is the full updated code:无论如何,更新 function 在Text class 中不起作用,这里是完整的更新代码:

from ursina import *

app = Ursina()
BUTTON_INDENT = -1
class TIME(Text):
    
    def __init__(self):

        super().__init__()
        self.text=time.strftime("%H:%M:%S")
        self.position=(0,0,BUTTON_INDENT)


t = TIME()

def update():
    t.text = time.strftime("%H:%M:%S")

app.run()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM