def load_excel(self, filename,menu_label): self.la=menu_label self.workbook = xl.load_workbook(filename) self.sheet_names = self.workbook.sheetnames # 清空左侧面板 for widget in self.panel_left.winfo_children(): widget.destroy() # 添加工作表按钮 style = ttk.Style() style.configure('my.TButton', font=('Arial', 10)) style.map('my.TButton', background=[('active', '#007FFF')]) for i, sheet_name in enumerate(self.sheet_names): button = ttk.Button(self.panel_left, text=sheet_name, command=lambda name=sheet_name: self.show_sheet(name), style='my.TButton') button.used = False button.grid(row=i, column=0, sticky="ew", padx=2, pady=2) button.bind("<Enter>", lambda event, button=button: button.config(relief="sunken")) button.bind("<Leave>", lambda event, button=button: button.config(relief="raised")) button.bind("<Button-1>", lambda event, button=button: mark_used(button)) def mark_used(button): # 将按钮的标记设置为“已使用” button.used = True # 更改按钮的背景颜色 button.configure(bg="gray") for child in self.panel_left.winfo_children(): # 绑定按钮的点击事件 child.bind("<Button-1>", lambda event, button=child: mark_used(button))報這個錯誤self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: unknown option "-relief"怎麽修改
时间: 2024-02-09 15:12:02 浏览: 74
Read data from the Excel spreadsheet.zip_Spreadsheet::Read_excel
你可以使用 `button.config(borderwidth=2)` 和 `button.config(relief="groove")` 来替换 `button.config(relief="sunken")` 和 `button.config(relief="raised")`。这样当你鼠标进入按钮时,它的外观将会变化。修改后的代码如下:
```
def load_excel(self, filename,menu_label):
self.la=menu_label
self.workbook = xl.load_workbook(filename)
self.sheet_names = self.workbook.sheetnames
# 清空左侧面板
for widget in self.panel_left.winfo_children():
widget.destroy()
# 添加工作表按钮
style = ttk.Style()
style.configure('my.TButton', font=('Arial', 10))
style.map('my.TButton', background=[('active', '#007FFF')])
for i, sheet_name in enumerate(self.sheet_names):
button = ttk.Button(self.panel_left, text=sheet_name, command=lambda name=sheet_name: self.show_sheet(name),
style='my.TButton')
button.used = False
button.grid(row=i, column=0, sticky="ew", padx=2, pady=2)
button.config(borderwidth=2)
button.config(relief="groove")
def mark_used(button):
# 将按钮的标记设置为“已使用”
button.used = True
# 更改按钮的背景颜色
button.configure(bg="gray")
# 绑定按钮的点击事件
button.bind("<Button-1>", lambda event, button=button: mark_used(button))
button.bind("<Enter>", lambda event, button=button: button.config(relief="sunken"))
button.bind("<Leave>", lambda event, button=button: button.config(relief="raised"))
```
这样应该可以解决你的问题。
阅读全文