#显示在当前情况下仓库中成品现存情况 import tkinter as tk from tkinter import ttk from tkinter import * #导入tkinter from tkinter import messagebox #引入弹出框 #from typing import Any, Union import pymysql #导入pymysql from pymysql.cursors import Cursor #导入游标 from hashlib import sha1 #导入hashlib,引用函数 from PIL import Image #图像缩放 from tkinter import Scrollbar from tkinter.ttk import Treeview import datetime window=tk.Tk() window.title('库存与存货管理-成品') window.geometry('1200x600-100-100') window['bg'] = 'Beige' window.resizable(False, False)#不允许改变窗口大小 class ChengPin: def __init__(self,window): self.conn = pymysql.Connect( host='localhost', port=3306, user='root', passwd='12345', db='库存与存货系统', charset="utf8" ) #Label ChengPin_name_Label=tk.Label(window,text='成品清单',font=('Arial',25),bg= 'Beige') ChengPin_name_Label.place(x=350,y=15) ChengPin_date_Label=tk.Label(window,text='日期:',font=('Arial',12),bg= 'Beige') ChengPin_date_Label.place(x=100,y=80) ChengPin_warehouse_Label=tk.Label(window,text='仓库:',font=('Arial',12),bg= 'Beige') ChengPin_warehouse_Label.place(x=350,y=80) ChengPin_depart_Label=tk.Label(window,text='部门:',font=('Arial',12),bg= 'Beige') ChengPin_depart_Label.place(x=550,y=80) ChengPin_notes_Label=tk.Label(window,text='备注:',font=('Arial',12),bg= 'Beige') ChengPin_notes_Label.place(x=100,y=120) #详细 frame = tk.Frame(window) # 锁定框架 frame.place(x=85, y=200, width=620, height=230) scrollBarx = tk.Scrollbar(frame, orient='horizontal') # 定义滑动条 scrollBarx.pack(side=tk.BOTTOM, fill=tk.X) scrollBary = tk.Scrollbar(frame) scrollBary.pack(side=tk.RIGHT, fill=tk.Y) tree = ttk.Treeview(frame, show="headings", xscrollcommand=scrollBarx.set, yscrollcommand=scrollBary.set) scrollBarx['command'] = tree.xview # 根据视图x移动 scrollBary['command'] = tree.yview # 根据视图y移动 tree['columns'] = ('规格型号', '产品名称', '产品类别', '计量单位', '数量', '单价', '金额', '生产批号', '生产日期', '备注') tree.column('规格型号', width=160, anchor='center') tree.column('产品名称', width=160, anchor='center') tree.column('计量单位', width=100, anchor='center') tree.column('产品类别', width=120, anchor='center') tree.column('数量', width=120, anchor='center') tree.column('单价', width=120, anchor='center') tree.column('金额', width=160, anchor='center') tree.column('生产批号', width=160, anchor='center') tree.column('生产日期', width=160, anchor='center') tree.column('备注', width=160, anchor='center') tree.heading('规格型号', text='规格型号') tree.heading('产品名称', text='产品名称') tree.heading('计量单位', text='计量单位') tree.heading('产品类别', text='产品类别') tree.heading('数量', text='数量') tree.heading('单价', text='单价') tree.heading('金额', text='金额') tree.heading('生产批号', text='生产批号') tree.heading('生产日期', text='生产日期') tree.heading('备注', text='备注') cursor = self.conn.cursor() cursor.execute("select * from goods ") self.conn.commit() data = cursor.fetchall() print(data[1][1]) cursor = self.conn.cursor() cursor.execute("select count(*) from goods ") row1=cursor.fetchall() self.conn.commit() row=row1[0][0] int(row) print(row) #qud for i in range (row): print(data[1][1]) #测试 print(data[i][1] ) tree.insert('', 'end', values=(data[i][0], data[i][1], data[i][5], data[i][2], data[i][3], data[i][4],data[i][3]*data[i][4], data[i][7], data[i][6], data[i][9])) #tree.insert('', 'end', values=('%s', '%s', '%s', '%s', '%d', '%d', '%d', '%s', '%Y-%m-%d %H:%M:%S', '%s'),(data[0][1])) tree.insert('', 'end', values=('', '', '', '', '', '', '', '', '', '')) #def insert_product(): #tree.insert('', 'end', values=('', '', '', '', '', '', '', '')) tree.pack() def __Entry(self,window): ChengPin_date_Entry=tk.Entry(window,width=20) ChengPin_date_Entry.place(x=175,y=83) #window.ChengPin_date_Entry.insert('end', nowTime) ChengPin_warehouse_Entry=tk.Entry(window,width=15) ChengPin_warehouse_Entry.place(x=400,y=83) ChengPin_depart_Entry=tk.Entry(window,width=15) ChengPin_depart_Entry.place(x=600,y=83) ChengPin_notes_Entry=tk.Entry(window,width=75) ChengPin_notes_Entry.place(x=175,y=123) def out(): window.quit() def okk(): cursor = self.conn.cursor() cursor.execute("select * from goods " ) self.conn.commit() data = cursor.fetchall() print(data[1][1]) # 测试获取到数据 nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 现在时间 ChengPin_date_Entry.insert('end', nowTime) ChengPin_warehouse_Entry.insert('end', '成品仓库') ChengPin_depart_Entry.insert('end', '仓储部门') ChengPin_notes_Entry.insert('end', '该清单显示在当前时间情况下产品成品的相关库存信息!') tk.Button(window, text='确定', width=10, height=1, command=okk).place(x=200, y=440) tk.Button(window, text='退出', width=10, height=1, command=out).place(x=400, y=440) def show(self,window): self.__Entry(window) window.mainloop() ChengPin=ChengPin(window) ChengPin.show(window) window.mainloop()