When I press the main menu button, the menu opens, but I can continue to press the button.

you also might want to also check if the widget has already been added to the viewport, before you add it to the viewport