class LoginWindow: def init(self, master): self.master = master self.master.title("CQ SMT BL 監控平臺-003無紙化點檢系統") 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=10, pady=10) ttk.Entry(self.master, textvariable=self.username, width=50).grid(row=0, column=1, columnspan=1, padx=10, pady=10) ttk.Label(self.master, text="密碼:", width=10).grid(row=1, column=0, padx=10, pady=10) ttk.Entry(self.master, textvariable=self.password, show="*", width=50).grid(row=1, column=1, columnspan=1, padx=10, pady=10) style = ttk.Style() style.configure("TButton", background="#4CAF50", foreground="blue", font=("Helvetica", 12), width=10) ttk.Button(self.master, text="確認", command=self.login, style="TButton", width=20).grid(row=2, column=0, columnspan=1, padx=10, pady=10) ttk.Button(self.master, text="取消", command=self.master.destroy, style="TButton", width=20).grid(row=2, column=2, columnspan=1, padx=10, pady=10) # 设置列的宽度 self.master.grid_columnconfigure(0, weight=1) self.master.grid_columnconfigure(1, weight=1) self.master.grid_columnconfigure(2, weight=1)修改這段代碼中將這個窗口分成兩個面板,從文本標簽到按鈕中間分割
时间: 2024-03-05 16:52:12 浏览: 74
你可以使用 ttk.Panedwindow() 来将窗口分成两个面板。以下是修改后的代码:
```
class LoginWindow:
def __init__(self, master):
self.master = master
self.master.title("CQ SMT BL 監控平臺-003無紙化點檢系統")
self.master.geometry("300x250+400+250")
self.master.resizable(0, 0)
self.username = tk.StringVar()
self.password = tk.StringVar()
# 创建一个 Panedwindow,设置 orient 为水平方向
pw = ttk.Panedwindow(self.master, orient='horizontal')
pw.pack(fill='both', expand=True)
# 创建左侧面板
left_frame = ttk.Frame(pw, width=150, height=250, relief='sunken')
pw.add(left_frame)
# 创建右侧面板
right_frame = ttk.Frame(pw, width=150, height=250, relief='sunken')
pw.add(right_frame)
# 在左侧面板中添加控件
ttk.Label(left_frame, text="賬號:", width=10).grid(row=0, column=0, padx=10, pady=10)
ttk.Entry(left_frame, textvariable=self.username, width=50).grid(row=0, column=1, columnspan=1, padx=10, pady=10)
ttk.Label(left_frame, text="密碼:", width=10).grid(row=1, column=0, padx=10, pady=10)
ttk.Entry(left_frame, textvariable=self.password, show="*", width=50).grid(row=1, column=1, columnspan=1, padx=10, pady=10)
# 在右侧面板中添加控件
style = ttk.Style()
style.configure("TButton", background="#4CAF50", foreground="blue", font=("Helvetica", 12), width=10)
ttk.Button(right_frame, text="確認", command=self.login, style="TButton", width=20).grid(row=0, column=0, columnspan=1, padx=10, pady=10)
ttk.Button(right_frame, text="取消", command=self.master.destroy, style="TButton", width=20).grid(row=1, column=0, columnspan=1, padx=10, pady=10)
# 设置左右侧面板的列宽
left_frame.grid_columnconfigure(0, weight=1)
left_frame.grid_columnconfigure(1, weight=1)
right_frame.grid_columnconfigure(0, weight=1)
```
阅读全文