Tkinter check if entry box is empty

SkyDrive26 picture SkyDrive26 · Mar 16, 2013 · Viewed 40.1k times · Source

How to check if a Tkinter entry box is empty?

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

Answer

Bryan Oakley picture Bryan Oakley · Mar 16, 2013

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()