Popup Menu on/off with only one TextureButton

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cadam


I wanted to ask if there is a way to show a popup menu and hide it by clicking on the same button? Most of the tutorials use one button to call the menu and another one to hide/close it. I’m wondering how to achieve the same thing with just one button.

:bust_in_silhouette: Reply From: jgodfrey

Sure. Really, you just need to toggle the visibility of the PopupMenu with each button click. So…

  • Add a PopupMenu to the scene
  • Add a TextureButton to the scene
  • Add the following script to the parent of the above-mentioned controls (or change the script to as necessary)
  • Wire the pressed signal of the button to the the below function


func _on_TextureButton_pressed():
	$PopupMenu.visible = !$PopupMenu.visible

Wow that was quick!
And the best thing is: it worked! :wink:
Such a simple line…
Thank you so much!

cadam | 2020-12-07 23:05