0 votes

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

in Engine by (39 points)

1 Answer

0 votes
Best answer

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)
by (13,080 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.