Get button node in click event not working

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

How we can get the button reference on the event function that is connected?
My connect signals never works

extends PanelContainer

onready var hbox_container = $ScrollContainer/HBoxContainer
var btn 

func _ready():
	createbutton()


func createbutton():
	btn = Button.new()
	btn.set_name("button 1")
	btn.text = "button 1"
	hbox_container.add_child(btn)
	btn.connect("toggled", self, "button_toggled", [btn])

func button_toggled(toggled, target):
	print("which button = ", target.get_name())
	if toggled == true:
		print("Button ist pressed")
	else: 
		print("Button is released")

Any way at least to do this? Thank you very much!

:bust_in_silhouette: Reply From: njamster

Check out this question. As far as I know, it’s not possible from the GUI, but it can be easily achieved via scripting. An example script is provided in the linked question.

it works!
Thank you very much :slight_smile:

SamTT | 2020-02-18 14:58