class InventoryApp: def __init__(self, master): self.master = master master.title("物料进出库统计") # 创建容器,用于放置表格和文本框 self.container = tk.Frame(master,width=0.2) self.container.grid(row=0, column=0, padx=5, pady=5) # 创建容器,用于放置表格和文本框 self.container1 = tk.Frame(master) self.container1.grid(row=0, column=15, padx=5, pady=5) # 创建标签和文本框 self.label1 = tk.Label(self.container, text="物料名称:") self.label1.grid(row=0, column=0, padx=5, pady=5) self.material_name = tk.Entry(self.container, width=20) self.material_name.grid(row=0, column=1, padx=5, pady=5) self.label2 = tk.Label(self.container, text="数量:") self.label2.grid(row=1, column=0, padx=5, pady=5) self.material_qty = tk.Entry(self.container, width=20) self.material_qty.grid(row=1, column=1, padx=5, pady=5) # 创建进出库按钮 self.in_button = tk.Button(self.container, text="进库", command=self.in_stock) self.in_button.grid(row=2, column=0, padx=5, pady=5) self.out_button = tk.Button(self.container, text="出库", command=self.out_stock) self.out_button.grid(row=2, column=1, padx=5, pady=5) # 添加显示excel内容的按钮 self.show_button = tk.Button(self.container, text="显示Excel内容", command=self.show_excel) self.show_button.grid(row=3, column=0, columnspan=2, padx=5, pady=5) # 创建标签用于显示工作表名称 self.record_label = tk.Label(self.container1, text="記錄") self.record_label.grid(row=0, column=2, padx=5, pady=5) self.data_label = tk.Label(self.container1, text="數據") self.data_label.grid(row=2, column=2, padx=5, pady=5) # 打开Excel文件 self.wb = openpyxl.load_workbook(r"C:\Users\bing3_chen\Desktop\1.xlsx") self.record_sheet = self.wb["記錄"] self.data_sheet = self.wb["數據"]將這段代碼中第一個容器放到窗口左側,第2個容器放到窗口右側
时间: 2024-01-06 08:05:34 浏览: 99
可以将第一个容器的列改为0,第二个容器的列改为15,这样就可以分别放在窗口的左侧和右侧了。修改后的代码如下:
```
class InventoryApp:
def __init__(self, master):
self.master = master
master.title("物料进出库统计")
# 创建容器,用于放置表格和文本框
self.container = tk.Frame(master, width=0.2)
self.container.grid(row=0, column=0, padx=5, pady=5)
# 创建容器,用于放置表格和文本框
self.container1 = tk.Frame(master)
self.container1.grid(row=0, column=15, padx=5, pady=5)
# 创建标签和文本框
self.label1 = tk.Label(self.container, text="物料名称:")
self.label1.grid(row=0, column=0, padx=5, pady=5)
self.material_name = tk.Entry(self.container, width=20)
self.material_name.grid(row=0, column=1, padx=5, pady=5)
self.label2 = tk.Label(self.container, text="数量:")
self.label2.grid(row=1, column=0, padx=5, pady=5)
self.material_qty = tk.Entry(self.container, width=20)
self.material_qty.grid(row=1, column=1, padx=5, pady=5)
# 创建进出库按钮
self.in_button = tk.Button(self.container, text="进库", command=self.in_stock)
self.in_button.grid(row=2, column=0, padx=5, pady=5)
self.out_button = tk.Button(self.container, text="出库", command=self.out_stock)
self.out_button.grid(row=2, column=1, padx=5, pady=5)
# 添加显示excel内容的按钮
self.show_button = tk.Button(self.container, text="显示Excel内容", command=self.show_excel)
self.show_button.grid(row=3, column=0, columnspan=2, padx=5, pady=5)
# 创建标签用于显示工作表名称
self.record_label = tk.Label(self.container1, text="記錄")
self.record_label.grid(row=0, column=2, padx=5, pady=5)
self.data_label = tk.Label(self.container1, text="數據")
self.data_label.grid(row=2, column=2, padx=5, pady=5)
# 打开Excel文件
self.wb = openpyxl.load_workbook(r"C:\Users\bing3_chen\Desktop\1.xlsx")
self.record_sheet = self.wb["記錄"]
self.data_sheet = self.wb["數據"]
```
阅读全文