Skip to content Skip to sidebar Skip to footer

How Do I Check If Any Entry Boxes Are Empty In Tkinter?

I am making a GUI in Tkinter with Python 2.7. I have a frame with about 30 entry boxes among other things. I don't have access to the code right now, but is there a way to check if

Solution 1:

You can get the content of the entry using Tkinter.Entry.get method.

Check the length of the entry using len function and get method:

iflen(entry_object.get()) == 0:  # empty!# do something

or more preferably:

ifnot entry_object.get(): # empty! (empty stringisfalse value)
    # do something

Use for loop to check several entry widgets:

for entry in entry_list:
    ifnot entry_object.get():
        # empty!

You should populate entry_list beforehand.

Manually:

entry_list = []

entry = Entry(...)
...
entry_list.append(entry)

entry = Entry(...)
...
entry_list.append(entry)

or, using winfo_children method (to get all entries):

entry_list = [child for child in root_widget.winfo_children()
              if isinstance(child, Entry)]

Post a Comment for "How Do I Check If Any Entry Boxes Are Empty In Tkinter?"