EatMyApples
EatMyApples

Reputation: 475

Checking value of Tkinter Entry widget

I have a submit button here:

submit_btn = Button(top, text="Submit", width=10, command=callback)
submit_btn.grid(row=3, column=1)

and as soon as you click it, it should check the entry field above if the input == "Vincent".

This is the entry field:

top = Tk()
user_label = Label(top, text="User Name")
user_label.grid(row=0, column=0)
username = Entry(top, bd = 5)
username.grid(row=0, column=1)

Is there a way to check if the value of the 'username' Entry object is "Vincent"?

Upvotes: 1

Views: 5455

Answers (1)

David Cain
David Cain

Reputation: 17333

I believe this should do the trick.

submit_btn = Button(top, text="Submit", width=10, command=check_vincent)

def check_vincent():
    if username.get() == "Vincent":
        print "Hi, Vincent!"
    else:
        print "Where's Vincent?"

Upvotes: 5

Related Questions