You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

from tkinter import*
user_login ={'aaa':'123456', 'bbb':'888888', 'ccc':'333333', }
#定义登录次数
count =0
def login():
global count
username =entry_username.get ()
if username not in user_login:
label_message.config(text='账号错误!')
else:
password =entry_password.get ()
if (password ==user_login[username]):
label_message.config(text='登录成功!')
open_new_window()
else:
label_message.config(text='密码错误!还可以尝试{}'.format (2 -coum))
count = count +1
if count ==3:
label_message.config(text='登录失败!')
btn_login.config(state="disabled")
def open_new_window():
# 创建一个新窗口
new_window = Toplevel(window)
new_window.title("登录成功")
new_window.geometry("300x200")
Label(new_window, text="欢迎进入新页面!").pack()
window =Tk()
window.title("用户登录")
window.geometry("300x200")
#创建标签和输入框
label_username=Label(window, text="账号:")
label_username.pack()
entry_username =Entry (window)
entry_username.pack ()
label_password=Label (window, text="密码:")
label_password.pack ()
entry_password = Entry(window, show='*')
entry_password.pack()
#创建登录按钮和消息提示标签
btn_login =Button (window, text="登录", command=login)
btn_login.pack()
label_message = Label (window, text ="")
label_message.pack()
#运行主循环
window.mainloop ()