# 创建右侧面板 self.panel_right = tk.Frame(master) self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) # 创建文本框 self.textbox = tk.Text(self.panel_right) self.textbox.pack(side=tk.TOP, fill=tk.BOTH, expand=True) # 创建标签和下拉框 ri = datetime.datetime.now().strftime('%Y/%m/%d') values = [ri] self.label1 = tk.Label(self.panel_right, text="點檢日期") self.label1.pack(side=tk.TOP, padx=5, pady=5) self.combobox1 = tk.ttk.Combobox(self.panel_right, values=[values]) self.combobox1.pack(side=tk.TOP, padx=5, pady=5) self.combobox1.current(0) ri1 = datetime.datetime.now().strftime('%H:%M:%S') values3 = [ri1] self.label3 = tk.Label(self.panel_right, text="點檢人") self.label3.pack(side=tk.TOP, padx=5, pady=5) self.combobox3 = tk.ttk.Combobox(self.panel_right, values=values3) self.combobox3.pack(side=tk.TOP, padx=5, pady=5) self.combobox3.current(0)修改這個代碼將文本標簽和文本框對其
时间: 2023-11-29 19:06:49 浏览: 157
可以将文本标签和文本框都放在一个Frame中,然后设置Frame的对齐方式为左对齐:
```
# 创建右侧面板
self.panel_right = tk.Frame(master)
self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 创建Frame来包含标签和文本框
text_frame = tk.Frame(self.panel_right)
text_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
# 创建文本框
self.textbox = tk.Text(text_frame)
self.textbox.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
# 创建标签和下拉框
ri = datetime.datetime.now().strftime('%Y/%m/%d')
values = [ri]
self.label1 = tk.Label(text_frame, text="點檢日期")
self.label1.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox1 = tk.ttk.Combobox(text_frame, values=[values])
self.combobox1.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox1.current(0)
ri1 = datetime.datetime.now().strftime('%H:%M:%S')
values3 = [ri1]
self.label3 = tk.Label(text_frame, text="點檢人")
self.label3.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox3 = tk.ttk.Combobox(text_frame, values=values3)
self.combobox3.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox3.current(0)
```
这样文本标签和文本框就会左对齐了。
阅读全文