Search code examples
pythontkintertkinter-entry

Tkinter check if entry box is empty


How to check if a Tkinter entry box is empty?

In other words if it doesn't have a value assigned to it.


Solution

  • You can get the value and then check its length:

    if len(the_entry_widget.get()) == 0:
        do_something()
    

    You can get the index of the last character in the widget. If the last index is 0 (zero), it is empty:

    if the_entry_widget.index("end") == 0:
        do_something()