1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| import tkinter as tk from tkinter import messagebox
window = tk.Tk() window.geometry("500x250")
def check(strings, reason, id): if entry1.get() == "admin": messagebox.showinfo(title="正确", message="输入正确!") print(strings, reason, id) return True else: messagebox.showwarning(title="错误", message="输入错误!") print(strings, reason, id) return False
CheckTest = window.register(check)
label1 = tk.Label(window, text="账号:") label2 = tk.Label(window, text="密码:") label1.grid(row=0, padx=90, pady=20) label2.grid(row=1, padx=90, pady=20)
dystr = tk.StringVar()
entry1 = tk.Entry( window, textvariable=dystr,
validate="focusout",
validatecommand=(CheckTest, "%P", "%V", "%W"), ) entry2 = tk.Entry(window)
entry1.grid(row=0, column=1, padx=30) entry2.grid(row=1, column=1, padx=30)
window.mainloop()
|