test
# -*- coding:gb2312 -*- from tkinter import ttk from tkinter import * from tkinter import messagebox class JXC(object): def __init__(self): self.index = 0 '''初始顶层框架''' self.top = Tk() self.top.title('简易进销存 1.0') self.top.geometry('600x400') """set start page Label""" self.startLabel = Label(self.top, text='简易进销存 ', font=('Arial',16,'bold')) self.startLabel.pack(fill=X, expand=0) """set options button """ self.optFrm = Frame(self.top, height=10) self.optFrm.pack(fill=X,expand=0) self.startBtn = Button(self.optFrm, text='首页',width=10,command=self.showStartFrm) self.startBtn.pack(side=LEFT) self.buyBtn = Button(self.optFrm, text='进货信息',width=10,command=self.showBuyFrm) self.buyBtn.pack(side=LEFT) self.sellBtn = Button(self.optFrm, text='出货信息',width=10,command=self.showSellFrm) self.sellBtn.pack(side=LEFT) self.queryBtn = Button(self.optFrm, text='查询',width=10,command=self.showQueryFrm) self.queryBtn.pack(side=LEFT) """start page Frame""" self.startFrm = Frame(self.top) """buy page Frame""" self.buyFrm = Frame(self.top) """sell page Frame""" self.sellFrm = Frame(self.top) """sell query Frame""" self.queryFrm = Frame(self.top) def showStartFrm(self): self.startFrm.pack(fill='both',expand=1) self.buyFrm.pack_forget() self.sellFrm.pack_forget() self.queryFrm.pack_forget() def showBuyFrm(self): self.startFrm.pack_forget() self.buyFrm.pack(fill='both', expand=1) self.sellFrm.pack_forget() self.queryFrm.pack_forget() def showSellFrm(self): self.startFrm.pack_forget() self.buyFrm.pack_forget() self.sellFrm.pack(fill='both', expand=1) self.queryFrm.pack_forget() def showQueryFrm(self): self.startFrm.pack_forget() self.buyFrm.pack_forget() self.sellFrm.pack_forget() self.queryFrm.pack(fill='both', expand=1) def setStartSubFrm(self): illustrationText = """" a b c """ self.illustrLabel = Label(self.startFrm,text = illustrationText,font=('Arial',14,'bold')) self.illustrLabel.pack() def setBuyOrSellSubFrm(self, root, BuyOrSell): if BuyOrSell: option = ['物品名称','物品编号','进货价格','进货数量','进货厂商'] labelText = ['添加新的进货订货单', '已添加的进货订单'] else: option = ['物品名称','物品编号','销售价格','销售数量','客户信息'] labelText = ['添加新的销售订货单', '已添加的销售订单'] self.subFrmUp = Frame(root) self.subFrmUp.pack(fill=X,expand=0) self.subFrmDown = Frame(root) self.subFrmDown.pack(fill=X,expand=0) self.addInfoLabel = Label(self.subFrmUp, text=labelText[0], font=('Arial', 14, 'bold')) self.addInfoLabel.pack(fill=X,expand=0) self.subFrmUpOperate = Frame(self.subFrmUp,bg='red') self.subFrmUpOperate.pack() self.showInfoLabel = Label(self.subFrmDown,text=labelText[1],font=('Arial',14,'bold')) self.showInfoLabel.pack(fill=X,expand=0) self.subFrmDownShow = Frame(self.subFrmDown,bg='red') self.subFrmDownShow.pack() """Input""" self.itemLabel = Label(self.subFrmUpOperate,text=option[0], font=('Arial', 12),width=15) self.itemLabel.grid(row=1, column=0,columnspan=15) self.identLabel = Label(self.subFrmUpOperate,text=option[1], font=('Arial', 12),width=15) self.identLabel.grid(row=2, column=0, columnspan=15) self.priLabel = Label(self.subFrmUpOperate,text=option[2], font=('Arial', 12),width=15) self.priLabel.grid(row=3, column=0, columnspan=15) self.numLabel = Label(self.subFrmUpOperate,text=option[3], font=('Arial', 12),width=15) self.numLabel.grid(row=4, column=0, columnspan=15) self.whereLabel = Label(self.subFrmUpOperate,text=option[4], font=('Arial', 12),width=15) self.whereLabel.grid(row=5, column=0, columnspan=15) self.itemEntry = Entry(self.subFrmUpOperate,text=option[0], font=('Arial', 12),width=15) self.itemEntry.grid(row=1, column=15, columnspan=15) self.identEntry = Entry(self.subFrmUpOperate,text=option[1], font=('Arial', 12),width=15) self.identEntry.grid(row=2, column=15, columnspan=15) self.priEntry = Entry(self.subFrmUpOperate,text=option[2], font=('Arial', 12),width=15) self.priEntry.grid(row=3, column=15, columnspan=15) self.numEntry = Entry(self.subFrmUpOperate,text=option[3], font=('Arial', 12),width=15) self.numEntry.grid(row=4, column=15, columnspan=15) self.whereEntry = Entry(self.subFrmUpOperate,text=option[4], font=('Arial', 12),width=15) self.whereEntry.grid(row=5, column=15, columnspan=15) self.clcBtn = Button(self.subFrmUpOperate,text='Clear',activebackground='gray',command=self.clearEntry) self.clcBtn.grid(row=6,column=13,columnspan=5) self.saveBtn = Button(self.subFrmUpOperate,text='Save',activebackground='gray',command=self.showInfo) self.saveBtn.grid(row=6,column=18,columnspan=5) """show""" self.tree = ttk.Treeview(self.subFrmDownShow) self.tree['column'] = tuple(option) for item in option: self.tree.column(item,minwidth=0,width=200) self.tree.heading(item,text=item) self.tree.pack() def setQueryFrm(self): self.queryUpFrm = Frame(self.queryFrm) self.queryUpFrm.pack(fill=X,expand=0) self.queryDownFrm = Frame(self.queryFrm) self.queryDownFrm.pack(fill=X, expand=0) self.queryUpInfoLabel = Label(self.queryUpFrm,text='Data') self.queryUpInfoLabel.grid(row=0,column=0,columnspan=5) self.queryUpEntryFirst = Entry(self.queryUpFrm) self.queryUpEntryFirst.grid(row=0,column=10,columnspan=5) self.queryUpInfoLabel = Label(self.queryUpFrm, text='---') self.queryUpInfoLabel.grid(row=0, column=16, columnspan=2) self.queryUpEntrySecond= Entry(self.queryUpFrm) self.queryUpEntrySecond.grid(row=0, column=18, columnspan=5) self.queryUpInfoBtn = Button(self.queryUpFrm, text='Query',activebackground='gray',command = self.queryData) self.queryUpInfoBtn.grid(row=0, column=25, columnspan=5) self.tree = ttk.Treeview(self.queryDownFrm) option = ['物品名称','物品编号','物品价格','进货数量','进货厂商','销售价格','销售数量','客户信息','库存信息'] self.tree['column'] = option for item in option: self.tree.heading(item,text=item) self.tree.column(item,minwidth=0,width=100) self.tree.pack() def get_input(self): newInput = [] newInput.append(self.itemEntry.get()) newInput.append(self.identEntry.get()) newInput.append(self.priEntry.get()) newInput.append(self.numEntry.get()) newInput.append(self.whereEntry.get()) return newInput def clearEntry(self): self.itemEntry.delete(0,END) self.identEntry.delete(0, END) self.priEntry.delete(0, END) self.numEntry.delete(0, END) self.whereEntry.delete(0, END) def queryData(self): startDate = self.queryUpEntryFirst.get() endDate = self.queryUpEntrySecond.get() if endDate>startDate: queryData = self.readData(startDate,endDate) self.queryUpEntryFirst.delete(0, END) self.queryUpEntrySecond.delete(0, END) return [] #return queryData else: messagebox.showinfo('Error','Date Error') self.queryUpEntryFirst.delete(0,END) self.queryUpEntrySecond.delete(0, END) def updateTree(self,order): self.tree.insert('',self.index,text=self.index,values=order) self.index += 1 def readData(self,startDate,endDate): pass def writeData(self,order): pass def showInfo(self): val = messagebox.askyesno('警告','保存该订单信息?') if val: messagebox.showinfo('提示','订单信息保存成功!') order = self.get_input() self.clearEntry() self.updateTree(order) self.writeData(order) def start(self): self.index = 0 self.setQueryFrm() self.setStartSubFrm() self.setBuyOrSellSubFrm(self.buyFrm,1) self.setBuyOrSellSubFrm(self.sellFrm,0) self.showStartFrm() self.top.mainloop() def main(): jxc = JXC() jxc.start() if __name__=='__main__': main()