尝试使用Tkinter和customtkinter来做各种密码检查,即使有正确的用户名和密码,我得到访问被拒绝.我尝试使用几种不同的方式和方法,我尝试做它没有Tkinter和它工作正常,Idk为什么它不工作
`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()`
2条答案
按热度按时间xdyibdwo1#
您应该使用.get,因此代码应该如下所示:
5rgfhyps2#
好的,找到了答案,我显然用错了.get()函数。谢谢你的帮助!