class LoginWindow: def init(self, master): self.master = master self.master.title("BL 製造表單點檢系統") self.master.geometry("300x250+400+250") self.master.resizable(0, 0) self.username = tk.StringVar() self.password = tk.StringVar() ttk.Label(self.master, text="賬號", width=10).grid(row=2, column=0, padx=5, pady=5) ttk.Entry(self.master, textvariable=self.username, width=20).grid(row=2, column=1, columnspan=2, padx=5, pady=5) ttk.Label(self.master, text="密碼", width=10).grid(row=3, column=0, padx=5, pady=5) ttk.Entry(self.master, textvariable=self.password, show="*", width=20).grid(row=3, column=1, columnspan=2, padx=5, pady=5) style = ttk.Style() style.configure("TButton", background="#4CAF50", foreground="white", font=("Helvetica", 12), width=10) ttk.Button(self.master, text="確認", command=self.login, style="TButton").grid(row=4, column=0, columnspan=2, padx=5, pady=5) # 设置列的宽度 self.master.grid_columnconfigure(0, weight=1) self.master.grid_columnconfigure(1, weight=1) self.master.grid_columnconfigure(2, weight=1) def login(self): if self.username.get() == "smt" and self.password.get() == "bl": self.master.destroy() root = tk.Tk() app = ExcelApp(root) root.mainloop() else: messagebox.showwarning("Invalid Credentials", "密碼或賬號錯誤.")讓這個代碼的文本框與標簽修改得近一些
时间: 2024-04-28 15:20:25 浏览: 104
python 中-self-标识符和self标识符.docx
class LoginWindow:
def __init__(self, master):
self.master = master
self.master.title("BL 製造表單點檢系統")
self.master.geometry("300x250+400+250")
self.master.resizable(0, 0)
self.username = tk.StringVar()
self.password = tk.StringVar()
ttk.Label(self.master, text="賬號", width=10).grid(row=0, column=0, padx=5, pady=5)
ttk.Entry(self.master, textvariable=self.username, width=20).grid(row=0, column=1, columnspan=2, padx=5, pady=5)
ttk.Label(self.master, text="密碼", width=10).grid(row=1, column=0, padx=5, pady=5)
ttk.Entry(self.master, textvariable=self.password, show="*", width=20).grid(row=1, column=1, columnspan=2, padx=5, pady=5)
style = ttk.Style()
style.configure("TButton", background="#4CAF50", foreground="white", font=("Helvetica", 12), width=10)
ttk.Button(self.master, text="確認", command=self.login, style="TButton").grid(row=2, column=1, columnspan=2, padx=5, pady=5)
# 设置列的宽度
self.master.grid_columnconfigure(0, weight=1)
self.master.grid_columnconfigure(1, weight=1)
self.master.grid_columnconfigure(2, weight=1)
def login(self):
if self.username.get() == "smt" and self.password.get() == "bl":
self.master.destroy()
root = tk.Tk()
app = ExcelApp(root)
root.mainloop()
else:
messagebox.showwarning("Invalid Credentials", "密碼或賬號錯誤.")
阅读全文