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()`
CodePudding user response:
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")
CodePudding user response:
Okay, Found an Answer for it, I was using the .get() function in the wrong way apparently. Thanks for the help though!