def show_data(self, sheet_name): try: # 读取工作表中一行数据 df = pd.read_excel(self.file_name, sheet_name=sheet_name) row = df.iloc[0] # 在日志框中显示数据 self.log_text.delete(1.0, tk.END) for i, column_name in enumerate(df.columns): self.log_text.insert(tk.END, f"{column_name}: {row[column_name]}\n") # 根据数据内容自动添加下拉框和滑动条 if isinstance(row[column_name], (int, float)): scale = ttk.Scale(self.log_text, from_=0, to=row[column_name], orient=tk.HORIZONTAL) scale.pack(side=tk.TOP, fill=tk.X, padx=10) elif isinstance(row[column_name], str): combobox = ttk.Combobox(self.log_text, values=["Option 1", "Option 2", "Option 3"]) combobox.pack(side=tk.TOP, fill=tk.X, padx=10) except Exception as e: self.log_text.insert(tk.END, str(e) + "\n")這就代碼中下拉輸入框遮到數據内容了,怎麽修改
时间: 2023-12-04 20:06:03 浏览: 116
解决python pandas读取excel中多个不同sheet表格存在的问题
5星 · 资源好评率100%
您可以将下拉框和滑动条放在数据内容下面,例如使用一个Frame来包含每个数据内容和相应的下拉框/滑动条,然后将所有这些Frame添加到主窗口中。代码示例:
```
def show_data(self, sheet_name):
try:
# 读取工作表中一行数据
df = pd.read_excel(self.file_name, sheet_name=sheet_name)
row = df.iloc[0]
# 清空日志框
self.log_text.delete(1.0, tk.END)
# 创建一个Frame来包含每个数据内容和相应的下拉框/滑动条
frame_list = []
for i, column_name in enumerate(df.columns):
frame = tk.Frame(self.log_text)
frame.pack(side=tk.TOP, fill=tk.X, padx=10, pady=(5, 0))
label = tk.Label(frame, text=f"{column_name}: {row[column_name]}")
label.pack(side=tk.LEFT)
if isinstance(row[column_name], (int, float)):
scale = ttk.Scale(frame, from_=0, to=row[column_name], orient=tk.HORIZONTAL)
scale.pack(side=tk.RIGHT, fill=tk.X, expand=True)
elif isinstance(row[column_name], str):
combobox = ttk.Combobox(frame, values=["Option 1", "Option 2", "Option 3"])
combobox.pack(side=tk.RIGHT, fill=tk.X, expand=True)
frame_list.append(frame)
except Exception as e:
self.log_text.insert(tk.END, str(e) + "\n")
```
阅读全文