本帖最後由 tonyh 於 2023-7-20 16:06 編輯
- import tkinter as tk
- import tkinter.messagebox as tmbox
- def check():
- if name.get()=="Tony" and pw.get()=="456789":
- tmbox.showinfo(title="驗證結果",message="您好,{}!".format(name.get()))
- else:
- tmbox.showinfo(title="驗證結果",message="驗證失敗!")
-
- def clear():
- name.set("")
- pw.set("")
- win=tk.Tk()
- win.title("身份驗證")
- win.resizable(0,0)
- name=tk.StringVar()
- pw=tk.StringVar()
- fm=tk.Frame(win)
- lb=tk.Label(fm, text="來訪者:",width=7, anchor="e").pack(side="left")
- et=tk.Entry(fm, textvariable=name).pack(side="left", padx=10, pady=10)
- fm.pack()
- fm=tk.Frame(win)
- lb=tk.Label(fm, text="密碼:", width=7, anchor="e").pack(side="left")
- et=tk.Entry(fm, textvariable=pw, show="*").pack(side="left", padx=10)
- fm.pack()
- fm=tk.Frame(win)
- btn=tk.Button(fm, text="確定", width=12, bg="#CCEEFF", command=check).pack(side="left", padx=5, pady=20)
- btn=tk.Button(fm, text="清除", width=12, bg="#CCEEFF", command=clear).pack(side="left", padx=5, pady=20)
- fm.pack()
- win.mainloop()
複製代碼 |