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.

45 lines
1.4 KiB

from tkinter import*
import tkinter as tk
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='登录成功!')
def open_new_window():
new_window = tk.Toplevel(root)
# 在新窗口中创建新的界面
root = tk.Tk()
button = tk.Button(root, text="Open New Window", command=open_new_window)
button.pack()
root.mainloop()
else:
label_message.config(text='密码错误!还可以尝试{}'.format(2-count))
count=count+1
if count == 3:
label_message.config(text='登录失败!')
btn_login.config(state='disabled')
window = Tk()
window.title('用户登录')
window.geometry('300x200')
label_username=Label(window,text="账号:")
label_username.pack()
entry_username = Entry(window)
entry_username.pack()
label_passsword = Label(window,text="密码:")
label_passsword.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()