[SOLVED] Bgui question 2 - How to make frame to disappear/appear during game

I’ve been trying to figure out how to make a simple bgui Frame to appear/disappear with a press of a button.
I have root Frame which has an Inventory frame in it. I just haven’t managed to make the frame to be visible/not visible.

I have managed to get so far so that it appears, but then it won’t disappear again.
Sample code under:


self.frame_inventory = bgui.Frame(self.root, 'frame_inventory', border=1,
                                               pos=[screenXpx*16, screenYpx*80], size=[0.3, 0.3])

#Button's command function
def button_click(self, widget):
    if bge.logic.globalDict['inventory_show'] == False:
        bge.logic.globalDict['inventory_show'] = True
    else:
        bge.logic.globalDict['inventory_show'] = False

...and this is where it runs to a wall for me. I can't figure out how to remove the self.frame_inventory while running the game :).


You should be able to just set the visible property of the frame:



self.frame_inventory.visible = False # Or 0


if the values of a variable is True/False only avoid code like this:


if variable == False:

As the variable is boolean already you can use it as condition:


if variable:

Beside that I do not know if you can remove existing widgets from the BGUI instance. The documentation does not mention this option (Or I can’t see it).

SolarLunes suggestion makes the widget invisible. This might produce problems when adding more widgets without removing the invisible ones.

Ah this is exactly what I need. Thank you!