Check if LineEdit is empty.

Godot Version

v4.3.stable.official [77dcf97d8]

Question

I am making a game and want to check if a LineEdit is empty. What are some ways I can achieve this?

The .text property contains whatever has been entered, so if it’s empty, it should be "". If your label is called foo, you can:

if foo.text.is_empty():
    print("nothing!")
else:
    print("something: '%s'" % text.label)

I used the name and it says it is not declared in the current scope. How can I fix that?

In hexgrid’s example, foo is not the name of the label, but the variable containing a reference to the label. If the script that checks if the LineEdit is empty is on the LineEdit, you can use text directly. Otherwise, you need the NodePath to the LineEdit. For example, if the LineEdit is a direct chld of the current script’s node:

if $LineEdit.text.is_empty():