-2

I am trying to create a standard user ID/PASS login. When I use the next function to check if the entered password and name are right, I always get the "wrong values entered" message. Basically, the variables entry_1 and entry_2 are not storing the input text and I want a solution for that. Maybe any of you guys might propose a solution for that?

I have tried to assign entry_1 and entry_2 to variables but it did'nt work out.

from tkinter import *

root = Tk() # creates a window and initializes the interpreter
root.geometry("500x300")

name = Label(root, text = "Name")
password = Label(root, text = "Password")
entry_1 = Entry(root)
entry_2 = Entry(root)



name.grid(row = 0, column = 0, sticky = E) # for name to be at right use sticky = E (E means east)
entry_1.grid(row = 0, column =1)
x = "Taha"
password.grid(row = 1, column = 0)
entry_2.grid(row = 1, column =1)
y = "123"
c = Checkbutton(root, text = "Keep in logged in").grid(columnspan = 2 ) # mergers the two columns


def next():
    if a == entry_1 and b == entry_2:
        print ("Proceed")
    else:
        print("wrong values entered")

def getname():
    return name


Next = Button(root, text = "Next", command=next).grid(row = 3, column = 1)




root.mainloop() # keep runing the code

I want the program to return "Proceed" once correct values are entered.

Taha Khan
  • 3
  • 2

2 Answers2

1

in your code you're not checking for the user input anywhere. You should use get() to return user input. I've modified your code accordingly. Now if you enter Taha as username and 123 as password, you'll get the "Proceed" message.

from tkinter import *

root = Tk()  # creates a window and initializes the interpreter
root.geometry("500x300")

name = Label(root, text="Name")
password = Label(root, text="Password")
entry_1 = Entry(root)
entry_2 = Entry(root)

name.grid(row=0, column=0, sticky=E)  # for name to be at right use sticky = E (E means east)
entry_1.grid(row=0, column=1)
x = "Taha"
password.grid(row=1, column=0)
entry_2.grid(row=1, column=1)
y = "123"
c = Checkbutton(root, text="Keep in logged in").grid(columnspan=2)  # mergers the two columns


def next_window():
    user_name = entry_1.get()
    user_pass = entry_2.get()
    if x == user_name and y == user_pass:
        print("Proceed")
    else:
        print("wrong values entered")


def get_name():
    return name


Next = Button(root, text="Next", command=next_window).grid(row=3, column=1)

root.mainloop()
0

thanks to the people who helped, with your help i could find the missing part in the code. i should have used .get() funtion in order to get the entered text back. here is the upgraded code with some improvements.

from tkinter import *

from tkinter import messagebox
root = Tk() # creates a window and initializes the interpreter
root.geometry("500x300")

name = Label(root, text = "Name")
password = Label(root, text = "Password")
entry_1 = Entry(root)
entry_2 = Entry(root)



name.grid(row = 0, column = 0, sticky = E) # for name to be at right use sticky = E (E means east)
entry_1.grid(row = 0, column =1)
x = "Taha"
password.grid(row = 1, column = 0)
entry_2.grid(row = 1, column =1)
y = "123"
c = Checkbutton(root, text = "Keep in logged in").grid(columnspan = 2 ) # mergers the two columns


def next():

    a = entry_1.get()
    b = entry_2.get()

    if a == "Taha" and b =="123":
        messagebox.showinfo("Login", "successfuly logged in ")
        root.destroy()
        print ("Proceed")
    else:
        messagebox.showerror("Error", "wrong values entered")
        print("wrong values entered")
        root.destroy()



Next = Button(root, text = "Next", command=next).grid(row = 3, column = 1)




root.mainloop() # keep runing the code
Taha Khan
  • 3
  • 2