Keypad that adds text with buttons

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

I need some help making a keypad that has buttons you press and then the text comes up in a textbox. I have the numbers working i just dont know how to make a backspace that will delete the last number
func _on_key_1_pressed(): var Keytext = get_node("Keys_entered") Keytext.set_text(str(Keytext.get_text(),"1"))
Thanks

:bust_in_silhouette: Reply From: jgodfrey

For the Backspace key, you really just need to remove the last character in the visible string (if it contains characters). Here’s a simple example using a button to add an “A” character, a button to “Delete” and a label to display the current text.

To use it, you’ll need a scene with the following nodes:

Control
    ButtonA
    ButtonDel
    Label

Just wire the pressed() event of the two buttons to their handler functions in the below script.

extends Control

func _on_ButtonA_pressed():
	$Label.text += "A"
	
func _on_ButtonDel_pressed():
	var txt = $Label.text
	if txt.length() > 0:
		$Label.text = txt.substr(0, txt.length() - 1)

thank you, just testing it out then ill mark as the answer

Ender | 2020-04-20 00:20

Thank you sir , exactly what I needed!

Ytachi1000 | 2023-01-21 10:40