Question about BGUI

Im building the GUI controller for my project and I have a question. In my GUI I’ve added a Menu which is displayed when the user hover the mouse over an icon. To achieve this I added a function to the the _on_hover property of an iconimage and it works perfectly. A new frame is displayed and this frame contains my menu.

self.iconbutton1 = bgui.ImageButton(, sub_theme='Menu',
                                        size=[0.04, 0.14], pos=[0.05, 0.05])
# .on_click_menubutton displays a menu
self.iconbutton1._on_hover = self.on_click_menubutton
# ._destroy_menu destroys the menu
self.iconbutton1._on_mouse_exit = self._destroy_menu

The problem is that when I use the _on_mouse_exit property to destroy the menu. To achieve this I use the visibility property of the menu frame, the program detects when the mouse exits the button but the menu remains there.

I attach the function which creates the menu and the one which should destroy it which I dont know cant destroy it.

Thanks a lot for your time

    def on_click_menubutton(self,widget):
        self.menufloat = bgui.Frame(self.frame, size=[.2, .4],pos=[0.05,0.5],

        self.button1 = bgui.FrameButton(self.menufloat, text='Opciones', size=[.7, .1], pos=[.15, .8],
            options = bgui.BGUI_DEFAULT)

        self.button2 = bgui.FrameButton(self.menufloat, text='Guardar', size=[.7, .1], pos=[.15, .6],
            options = bgui.BGUI_DEFAULT)

        self.button3 = bgui.FrameButton(self.menufloat, text='Menú principal', size=[.7, .1], pos=[.15, .4],
            options = bgui.BGUI_DEFAULT)

        self.button4= bgui.FrameButton(self.menufloat, text='Salir del programa', size=[.7, .1], pos=[.15, .2],
            options = bgui.BGUI_DEFAULT)

    def _destroy_menu(self,widget):
        self.menufloat.visible = False

Firstly, you should use

widget.on_hover = func

As opposed to

widget._on_hover = fun

Using the former will wrap the function call in a weak reference which is useful for garbage collecting.

Secondly, I don’t think you should be using the on_hover callback. The on_hover callback is called for every logic tick that the mouse is inside the widget. So you are actually re creating menufloat, button1, button2, button3 and button4 once per logic tick and when the mouse exits the widget only the last created group of those widgets gets removed.

Try using the on_mouse_enter callback

self.iconbutton1.on_mouse_enter = self.on_click_menubutton

Thats a nice idea thanks a lot for your help :slight_smile: