Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My Password Checker using Tkinter is not working

Tried to use Tkinter and customtkinter to make a Password checker of sorts, Even with the correct Username and Password, I get Access Denied. I tried using several different ways and methods and I tried to do it without Tkinter and It worked fine, Idk why its not working

`import tkinter
import customtkinter
from PIL import ImageTk,Image
from pyttsx3 import *

customtkinter.set_appearance_mode("System") 
customtkinter.set_default_color_theme("blue") 


app = customtkinter.CTk() 
app.geometry("1920x1080")
app.attributes('-fullscreen',True)
app.title('Login')
n=0
USRd={"Goop": "S311","Drep": "S456"}

img1=ImageTk.PhotoImage(Image.open("Wallpaper.png"))
l1=customtkinter.CTkLabel(master=app,image=img1)
l1.pack()

frame=customtkinter.CTkFrame(master=l1, width=320, height=360, corner_radius=15)
frame.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

l2=customtkinter.CTkLabel(master=frame, text="Log into your Account",font=('Century Gothic',20))
l2.place(x=50, y=45)

user = customtkinter.StringVar(value='')
entry1 = customtkinter.CTkEntry(
    master=frame,
    width=220,
    placeholder_text='Username',
    textvariable=user,
)
entry1.place(x=50, y=110)
user=entry1.get()

passw = customtkinter.StringVar(value='')
entry2=customtkinter.CTkEntry(master=frame, width=220, placeholder_text='Password', textvariable=passw)
entry2.place(x=50, y=165)
passw=entry2.get()

def button_function():
    for k in USRd:
        if (user==k) and (passw==USRd[k]):
            speak("Access Granted")
            x="Welcome back", k, "You have", USRd[k],"Notifications"
            speak(x)
            app.destroy()
            w = customtkinter.CTk()
            w.geometry("1280x720")
            w.title('Welcome')
            l1=customtkinter.CTkLabel(master=w, text=x ,font=('Century Gothic',60))
            l1.place(relx=0.5, rely=0.5,  anchor=tkinter.CENTER)
            w.mainloop()
        else:
            speak("Access Nope")

button1 = customtkinter.CTkButton(master=frame, width=220, text="Login", command=button_function, corner_radius=6)
button1.place(x=50, y=240)

if __name__ == "__main__":
    app.mainloop()`

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You should use .get,
so the code should look like this :-

def button_function():
    user=entry1.get()
    passw=entry2.get()
    for k in USRd:
        if (user==k) and (passw==USRd[k]):
            speak("Access Granted")
            x="Welcome back", k, "You have", USRd[k],"Notifications"
            speak(x)
            app.destroy()
            w = customtkinter.CTk()
            w.geometry("1280x720")
            w.title('Welcome')
            l1=customtkinter.CTkLabel(master=w, text=x ,font=('Century Gothic',60))
            l1.place(relx=0.5, rely=0.5,  anchor=tkinter.CENTER)
            w.mainloop()
        else:
            speak("Access Nope")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading