# 创建右侧面板 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)將標簽和下拉輸入框放到文本框上方
时间: 2024-02-03 12:12:32 浏览: 132
bst.rar_bst_bst tree
可以将文本框和标签/下拉框分别放到两个 Frame 中,然后将这两个 Frame 放到 self.panel_right 中即可。例如:
```
# 创建右侧面板
self.panel_right = tk.Frame(master)
self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 创建Frame来包含标签和下拉框
input_frame = tk.Frame(self.panel_right)
input_frame.pack(side=tk.TOP, fill=tk.X, padx=5, pady=5)
# 创建标签和下拉框
ri = datetime.datetime.now().strftime('%Y/%m/%d')
ri1 = datetime.datetime.now().strftime('%H:%M:%S')
self.label1 = tk.Label(input_frame, text="點檢日期")
self.label1.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox1 = tk.ttk.Combobox(input_frame, values=[ri])
self.combobox1.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox1.current(0)
self.label3 = tk.Label(input_frame, text="點檢人")
self.label3.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox3 = tk.ttk.Combobox(input_frame, values=[ri1])
self.combobox3.pack(side=tk.LEFT, padx=5, pady=5)
self.combobox3.current(0)
# 创建文本框
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)
```
这样,标签和下拉框会在一行中显示,位于文本框上方,而且在放大窗口时也会自动跟随变化。
阅读全文