self.username.grid(row=0, column=1, pady=(10, 6)) 这句代码什么意思
时间: 2024-05-27 19:09:23 浏览: 27
这句代码是在使用 tkinter 模块创建 GUI 界面时,将 `self.username` 对象放置在第 0 行第 1 列的位置,并设置上边缘与下边缘之间的垂直间距为 10,下边缘与下面对象之间的垂直间距为 6。通常情况下,`self.username` 对象应该是一个 tkinter 中的 Entry 或 Label 组件,用于显示和输入文本。
相关问题
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() tk.Label(self.master, text="賬號").grid(row=0, column=0, padx=5, pady=5) tk.Entry(self.master, textvariable=self.username).grid(row=0, column=1, padx=5, pady=5) tk.Label(self.master, text="密碼").grid(row=1, column=0, padx=5, pady=5) tk.Entry(self.master, textvariable=self.password, show="*").grid(row=1, column=1, padx=5, pady=5) tk.Button(self.master, text="確認", command=self.login).grid(row=2, column=0, columnspan=2, padx=5, pady=5) 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", "密碼或賬號錯誤.")將這段代碼的窗口優化得更美觀一些
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()
tk.Label(self.master, text="賬號").grid(row=0, column=0, padx=5, pady=5)
tk.Entry(self.master, textvariable=self.username, width=20).grid(row=0, column=1, padx=5, pady=5)
tk.Label(self.master, text="密碼").grid(row=1, column=0, padx=5, pady=5)
tk.Entry(self.master, textvariable=self.password, show="*", width=20).grid(row=1, column=1, padx=5, pady=5)
tk.Button(self.master, text="確認", command=self.login, width=20, bg="#4CAF50", fg="white").grid(row=2, column=0, columnspan=2, padx=5, pady=5)
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", "密碼或賬號錯誤.")
# 更改了输入框的宽度和按钮的颜色和宽度,使界面更美观
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", "密碼或賬號錯誤.")讓這個代碼的文本框與標簽修改得近一些
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", "密碼或賬號錯誤.")
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)