給這段代碼添加 儅用戶點擊按鈕時,將excel表名是出入庫明細數據以表格的方式顯示到第一個文本框中,表名是庫存明細的數據以表格的方式顯示到第二個文本框中,,數據是空的就是空,不要顯示字符出來,日期就顯示日期,不要將日期後面的時間顯示出來,因數據過大需要加水平滾動條和垂直滾動條在文本框的右側和底部,請給出添加后的代碼
时间: 2024-04-02 14:31:41 浏览: 68
Excel库存管理系统,最好用的Excel出入库管理表格
5星 · 资源好评率100%
class InventoryApp:
def __init__(self, master):
self.master = master
master.title("物料进出库统计")
master.state('zoomed') # 窗口最大化
# 创建右侧的工具栏
toolbar_frame = ttk.Frame(master, width=20)
toolbar_frame.pack(side='right', fill='y')
# 创建底部的工具栏
bottom_frame = ttk.Frame(master, height=20)
bottom_frame.pack(side='bottom', fill='x')
# 创建左侧面板
self.container = tk.Frame(master, width=100, bg='lightcyan')
self.container.pack(side=tk.LEFT, fill=tk.BOTH)
# 创建工具栏
toolbar = tk.Frame(master, height=0.2)
self.selected_label = tk.Label(toolbar, text="", fg="red", font=("Arial", 12))
self.selected_label.pack(side=tk.LEFT, padx=0.02, pady=0.02)
# 创建左上方面板
self.container_top = tk.Frame(self.container, width=100, bg='lightcyan')
self.container_top.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
# 创建左下方面板
self.container_bottom = tk.Frame(self.container, width=100, bg='lightcyan')
self.container_bottom.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
# 创建右侧面板
self.container1 = tk.Frame(master)
self.container1.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 打开Excel文件
self.wb = openpyxl.load_workbook('库存.xlsx')
self.record_sheet = self.wb["出入库明细"]
self.data_sheet = self.wb["库存明细"]
# 添加显示excel内容的按钮
self.show_button = tk.Button(self.container_bottom, text="显示Excel内容", command=self.show_excel)
self.show_button.grid(row=12, column=0, columnspan=2, padx=5, pady=5)
# 创建底部工具栏
bottom_toolbar = tk.Frame(master, bg='white')
bottom_toolbar.pack(side=tk.BOTTOM, fill=tk.X)
# 创建标签
label = tk.Label(self.container1, text="出入库明细")
label.pack(side=tk.TOP)
# 创建文本框1
text_frame = tk.Frame(self.container1)
text_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.result_text = tk.Text(text_frame, wrap=tk.NONE)
self.result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 创建水平滚动条
x_scroll = tk.Scrollbar(text_frame, orient=tk.HORIZONTAL)
x_scroll.pack(side=tk.BOTTOM, fill=tk.X)
x_scroll.config(command=self.result_text.xview)
# 创建垂直滚动条
y_scroll = tk.Scrollbar(self.container1, orient=tk.VERTICAL)
y_scroll.pack(side=tk.RIGHT, fill=tk.Y)
y_scroll.config(command=self.result_text.yview)
self.result_text.config(xscrollcommand=x_scroll.set, yscrollcommand=y_scroll.set)
# 创建标签2
label2 = tk.Label(self.container1, text="库存明细")
label2.pack(side=tk.TOP)
# 创建文本框2
text_frame2 = tk.Frame(self.container1)
text_frame2.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
self.result_text2 = tk.Text(text_frame2, wrap=tk.NONE)
self.result_text2.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 创建水平滚动条
x_scroll2 = tk.Scrollbar(text_frame2, orient=tk.HORIZONTAL)
x_scroll2.pack(side=tk.BOTTOM, fill=tk.X)
x_scroll2.config(command=self.result_text2.xview)
# 创建垂直滚动条
y_scroll2 = tk.Scrollbar(self.container1, orient=tk.VERTICAL)
y_scroll2.pack(side=tk.RIGHT, fill=tk.Y)
y_scroll2.config(command=self.result_text2.yview)
self.result_text2.config(xscrollcommand=x_scroll2.set, yscrollcommand=y_scroll2.set)
def show_excel(self):
# 清空文本框内容
self.result_text.delete(1.0, tk.END)
self.result_text2.delete(1.0, tk.END)
# 显示出入库明细
for row in self.record_sheet.iter_rows(values_only=True):
row_str = ""
for cell in row:
if cell is None:
cell = ""
elif type(cell) is datetime.datetime:
cell = cell.strftime("%Y-%m-%d")
row_str += str(cell) + "\t"
self.result_text.insert(tk.END, row_str + "\n")
# 显示库存明细
for row in self.data_sheet.iter_rows(values_only=True):
row_str = ""
for cell in row:
if cell is None:
cell = ""
elif type(cell) is datetime.datetime:
cell = cell.strftime("%Y-%m-%d")
row_str += str(cell) + "\t"
self.result_text2.insert(tk.END, row_str + "\n")
阅读全文