# 创建标签和下拉框 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) values=["唐彪", "汾陽", "劉永剛"] self.label2 = tk.Label(self.panel_right, text="點檢人") self.label2.pack(side=tk.TOP, padx=5, pady=5) self.combobox2 = tk.ttk.Combobox(self.panel_right, values=values) self.combobox2.pack(side=tk.TOP, padx=5, pady=5) self.combobox2.current(0)修改為橫著放
时间: 2023-11-14 08:05:31 浏览: 81
你可以使用 `tkinter` 中的 `grid()` 函数来实现横向排列。修改后的代码如下:
```
ri = datetime.datetime.now().strftime('%Y/%m/%d')
values = [ri]
self.label1 = tk.Label(self.panel_right, text="點檢日期")
self.label1.grid(row=0, column=0, padx=5, pady=5)
self.combobox1 = tk.ttk.Combobox(self.panel_right, values=[values])
self.combobox1.grid(row=0, column=1, 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.grid(row=1, column=0, padx=5, pady=5)
self.combobox3 = tk.ttk.Combobox(self.panel_right, values=values3)
self.combobox3.grid(row=1, column=1, padx=5, pady=5)
self.combobox3.current(0)
values=["唐彪", "汾陽", "劉永剛"]
self.label2 = tk.Label(self.panel_right, text="點檢人")
self.label2.grid(row=2, column=0, padx=5, pady=5)
self.combobox2 = tk.ttk.Combobox(self.panel_right, values=values)
self.combobox2.grid(row=2, column=1, padx=5, pady=5)
self.combobox2.current(0)
```
这样,三个标签与下拉框就可以横向排列了。
阅读全文