tkinter - How to have an event check an entry to see if it matches a variable in Python -
i'm wondering how have python check event see if username
, password
match, , print correct
if or false
if isn't. when try result false
. need way make check see if match.
here's code:
tkinter import * root = tk() def check(event): username = "amras" password = "pass" if entry1 == username: if entry2 == password: print("true") else: print("false") else: print("false") name = label(root, text="name: ") password = label(root, text="password: ") entry1 = entry(root) entry2 = entry(root) c = checkbutton(root, text="keep me logged in") button1 = button(root, text="login") button1.bind("<button-1>", check) name.grid(row=0, sticky=e) password.grid(row=1, sticky=e) entry1.grid(row=0, column=1) entry2.grid(row=1, column=1) c.grid(columnspan=2) button1.grid(row=1, column=2) root.mainloop()
you don't evaluate text put inside entry
box. use entry1.get()
etc...
from tkinter import * root = tk() def check(event): username = "amras" password = "pass" # these if statements should combined if entry1.get() == username: # use .get() method if entry2.get() == password: # use .get() method print("true") else: print("false") name = label(root, text="name: ") password = label(root, text="password: ") entry1 = entry(root) entry2 = entry(root) c = checkbutton(root, text="keep me logged in") button1 = button(root, text="login") button1.bind("<button-1>", check) name.grid(row=0, sticky=e) password.grid(row=1, sticky=e) entry1.grid(row=0, column=1) entry2.grid(row=1, column=1) c.grid(columnspan=2) button1.grid(row=1, column=2) root.mainloop()
not after type amras
, pass
in should true
also in code import statement seems bad (tkinter
capital default), there 2 else
statements in definition, , indentation wrong well.
Comments
Post a Comment