Search code examples
pythonuser-interfaceursina

Python Ursina hide UI


I have an GUI inventory and I don't know how to hide it and all the items there are inside. I tried to make the class Inventory(Entity) enabled or not and it didn't worked because it only gets enables and never disabled. This is my first post so, please, be nice.

My code:

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


app = Ursina()

class Inventory(Entity):
    def __init__(self):
        player.enabled = False
        super().__init__(
            parent = camera.ui,
            model = 'quad',
            scale = (.5, .8),
            origin = (-.5, .5),
            position = (-.3,.4),
            texture = 'white_cube',
            texture_scale = (5,8),
            color = color.dark_gray
            )

        self.item_parent = Entity(parent=self, scale=(1/5,1/8))
        enable = False


def input(key):

        if key == 'f':
            inventory_enable()


            
def inventory_enable():

    inventory = Inventory()
    Inventory().enable = False
    ...


Solution

  • Setting entity.enabled = False will deactivate it and all it's children. To make it reappear, set it back to True.