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, 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, 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-11-27 19:02:26 浏览: 75
解决python pandas读取excel中多个不同sheet表格存在的问题
5星 · 资源好评率100%
您可以将下拉框和滑动条放在日志框后面,代码如下:
```
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")
# 根据数据内容自动添加下拉框和滑动条
for i, column_name in enumerate(df.columns):
if isinstance(row[column_name], (int, float)):
scale = ttk.Scale(self, 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, 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")
```
这样,下拉框和滑动条就会在日志框后面显示了。
阅读全文