def show_sheet(self, sheet_name): self.textbox.tag_configure("left", justify="left") sheet = self.workbook[sheet_name] rows = sheet.max_row # 清空文本框 self.textbox.delete(1.0, tk.END) # 显示工作表内容 for row in sheet.iter_rows(values_only=True): line = "\t".join([str(cell) for cell in row]) + "\n" self.textbox.insert(tk.END, line) # 添加空白字符并设置标签 self.textbox.insert(tk.END, " " * 20, "combobox") self.textbox.insert(tk.END, sheet_name + ":\n", "left") # 创建下拉框并添加到文本框数据内容的后面 combobox = tk.ttk.Combobox(self.textbox, values=["下拉选项1", "下拉选项2", "下拉选项3"]) combobox.pack(side=tk.TOP, padx=10, pady=5) self.textbox.window_create(tk.END, window=combobox)修改這段代碼中文本框數據内容與下拉輸入框需要對齊
时间: 2024-01-01 11:06:39 浏览: 133
VB.password.TextBox.control.programming.model.rar_VB textbox
可以将创建下拉框的代码放在插入空白字符的前面,这样就能够保证文本框数据内容与下拉输入框对齐了。修改后的代码如下:
```
def show_sheet(self, sheet_name):
self.textbox.tag_configure("left", justify="left")
sheet = self.workbook[sheet_name]
rows = sheet.max_row
# 清空文本框
self.textbox.delete(1.0, tk.END)
# 添加空白字符并设置标签
self.textbox.insert(tk.END, sheet_name + ":\n", "left")
self.textbox.insert(tk.END, " " * 20, "combobox")
# 创建下拉框并添加到文本框数据内容的后面
combobox = tk.ttk.Combobox(self.textbox, values=["下拉选项1", "下拉选项2", "下拉选项3"])
combobox.pack(side=tk.TOP, padx=10, pady=5)
self.textbox.window_create(tk.END, window=combobox)
# 显示工作表内容
for row in sheet.iter_rows(values_only=True):
line = "\t".join([str(cell) for cell in row]) + "\n"
self.textbox.insert(tk.END, line)
```
阅读全文