Is there any way to delete a button after I press it

399 Views Asked by At

Is there any way that I can delete the b_render var when the b_logic function is activated? I have been trying different solutions for about an hour and nothing works. is there anything I overlooked?

from ursina import *

def b_logic():
    print("button pressed")

b_render = Button(scale = (.4,.1),color='red',text="start",on_click=b_logic)
3

There are 3 best solutions below

0
On

Yes, destroy(b_render) will remove the entity completely. If you plan to reuse the button later, I recommend setting .enabled to False instead.

1
On

I stuck at this when I was making a snake game.

from ursina import *

def b_logic():
    destroy(b_render) # if you do not want to use it later.
    # or
    # b_render.enabled = False

b_render = Button(scale = (.4,.1),color='red',text="start",on_click=b_logic)
0
On

You can destroy the button with the destroy() function:

def b_logic():
    print("button pressed")
    destroy(b_render)