self.button = tk.Label(input_frame,text="保存", command=self.save_to_excel).pack(side=tk.LEFT, padx=2,pady=2)報這個self.tk.call( _tkinter.TclError: unknown option "-command"
时间: 2024-02-09 07:11:12 浏览: 21
这个错误可能是由于你的 Tkinter 版本不支持 `command` 选项导致的。`command` 选项是用于将函数绑定到小部件上的选项。
请确保你正在使用的是支持 `command` 选项的 Tkinter 版本。如果你的 Tkinter 版本较旧,可以尝试更新它。如果你无法更新 Tkinter 版本,你可以使用 `bind` 方法将函数绑定到小部件上,例如:
```
self.button.bind("<Button-1>", self.save_to_excel)
```
这将在点击按钮时调用 `self.save_to_excel` 函数。
相关问题
self.label2 = tk.Label(input_frame, text="點檢時間") self.label2.pack(side=tk.LEFT, padx=0.02, pady=0.02) self.combobox2 = ttk.Combobox(input_frame) self.combobox2.pack(side=tk.LEFT, padx=0.02, pady=0.02) self.update_time() values = ["唐彪", "汾陽", "劉永剛"] self.label3 = tk.Label(input_frame, text="點檢人") self.label3.pack(side=tk.LEFT, padx=0.02, pady=0.02) self.combobox3 = tk.ttk.Combobox(input_frame, values=values) self.combobox3.pack(side=tk.LEFT, padx=0.02, pady=0.02) self.combobox3.current(0) values = ["D", "N"] self.label5 = tk.Label(input_frame, text="班別") self.label5.pack(side=tk.LEFT, padx=0.02, pady=0.02) self.combobox5 = tk.ttk.Combobox(input_frame, values=values) self.combobox5.pack(side=tk.LEFT, padx=0.05, pady=0.05) self.combobox5.current(0) values = [""] self.label6 = tk.Label(input_frame, text="機種") self.label6.pack(side=tk.LEFT, padx=0.05, pady=0.05) self.combobox6 = tk.ttk.Combobox(input_frame, values=values) self.combobox6.pack(side=tk.LEFT, padx=0.05, pady=0.05) self.combobox6.current(0)將下拉輸入框長度小一點
您可以使用 `width` 参数来设置下拉输入框的长度,例如:
```
self.combobox2 = ttk.Combobox(input_frame, width=10)
```
这将设置下拉输入框的宽度为 10 个字符。您可以根据需要进行调整。
# 创建右侧面板 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)將標簽和下拉輸入框放到文本框上方
可以将文本框和标签/下拉框分别放到两个 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)
```
这样,标签和下拉框会在一行中显示,位于文本框上方,而且在放大窗口时也会自动跟随变化。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)