Python Tkinter库存总额

2024-10-08 20:19:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,看到了一个关于使用tkinter制作的库存应用程序的源代码,我已经掌握了修改并试图理解代码的窍门,但是有些事情我似乎做不到,计算产品的总价(数量*价格)。当我将产品数量和产品价格相乘时,它返回0,因此我不知道如何将值赋给tkinter变量IntVar()。下面是所创建产品的viewform的代码:

def ViewForm():
global tree
TopViewForm = Frame(viewform, width=600, bd=1, relief=SOLID)
TopViewForm.pack(side=TOP, fill=X)
LeftViewForm = Frame(viewform, width=600)
LeftViewForm.pack(side=LEFT, fill=Y)
MidViewForm = Frame(viewform, width=600)
MidViewForm.pack(side=RIGHT)
lbl_text = Label(TopViewForm, text="View Products", font=('arial', 18), width=600)
lbl_text.pack(fill=X)
lbl_txtsearch = Label(LeftViewForm, text="Search", font=('arial', 15))
lbl_txtsearch.pack(side=TOP, anchor=W)
search = Entry(LeftViewForm, textvariable=SEARCH, font=('arial', 15), width=10)
search.pack(side=TOP,  padx=10, fill=X)
btn_search = Button(LeftViewForm, text="Search", command=Search)
btn_search.pack(side=TOP, padx=10, pady=10, fill=X)
btn_reset = Button(LeftViewForm, text="Reset", command=Reset)
btn_reset.pack(side=TOP, padx=10, pady=10, fill=X)
btn_delete = Button(LeftViewForm, text="Delete", command=Delete)
btn_delete.pack(side=TOP, padx=10, pady=10, fill=X)
scrollbarx = Scrollbar(MidViewForm, orient=HORIZONTAL)
scrollbary = Scrollbar(MidViewForm, orient=VERTICAL)
tree = ttk.Treeview(MidViewForm, columns=("ProductID", "Product Name", "Product Qty", "Product Price"), selectmode="extended", height=100, yscrollcommand=scrollbary.set, xscrollcommand=scrollbarx.set)
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM, fill=X)
tree.heading('ProductID', text="ProductID",anchor=W)
tree.heading('Product Name', text="Product Name",anchor=W)
tree.heading('Product Qty', text="Product Qty",anchor=W)
tree.heading('Product Price', text="Product Price",anchor=W)
tree.column('#0', stretch=NO, minwidth=0, width=0)
tree.column('#1', stretch=NO, minwidth=0, width=0)
tree.column('#2', stretch=NO, minwidth=0, width=200)
tree.column('#3', stretch=NO, minwidth=0, width=120)
tree.column('#4', stretch=NO, minwidth=0, width=120)
tree.pack()
DisplayData()

Tags: texttreetopcolumnproductwidthfillside

热门问题