小问题有大难度 高手们都来看看!!

_siiao 发布于 2015/06/15 12:07
阅读 367
收藏 0

下面是我自己做的一个类似收银的程序,可是在最后”remove“按键的时候,可以删除选择的东西,但是在total里面价钱没有删掉,怎么可以做到按了remove按钮,价钱也会同时删除呢?

import Tkinter

from Tkinter import *

import MySQLdb
window = Tkinter.Tk()
window.title("ETrolley")
window.geometry("500x360")
window.configure(bg="#cdc9c9")
title3=Label(window,text="",bg="#cdc9c9")
title1 = Label(window, text="------WELCOME TO ETrolley CHECKOUT------", bg="#cdc9c9")
title2 = Label(window, text="--Please scan your items--", bg="#cdc9c9")
barcodetitle = Label(window, text="---barcode---", bg="#cdc9c9")
itemtitle = Label(window, text="    Item_id    |    Item    |     Description     |    Price    ", bg="#cdc9c9")
barcode = Entry(window)
item = Text(window, height=4, width=35)
total = Text(window, height=1, width=5)
t1= Label (window,text="TOTAL", bg="#cdc9c9")
c1=Button(window,text="CHECKOUT",bg="#93ff00")
scroll = Scrollbar(window,orient=VERTICAL, bg="#93ff00")
scroll.config (command=item.yview)
item = Listbox(window,yscrollcommand=scroll.set,width=55,height=30,selectmode=EXTENDED)
title4=Label(window,text="",bg="#cdc9c9")
def one():

            user_input=barcode.get()        

            mycursor = db.cursor()

            mycursor.execute("""SELECT barcode, name, description,price FROM product

                         WHERE barcode = %s""", (user_input,))

            # calls fetchone until None is returned (no more rows)

            for row in iter(mycursor.fetchone, None):
                bar=row[0]
                name=row[1]
                des=row[2]
                pri=row[3]
               
                total.insert(END,row[3])


                item.insert(END,row)


                barcode.delete(0, 'end')  


def delete():


        item.delete(ACTIVE)

close = Button(window, text="remove",width=5, command=delete, bg="#ff4500")


go = Button(window, text="add!", command=one, bg="#93ff00")


title3.pack()


title1.pack()


title2.pack()

barcodetitle.pack()


barcode.pack(side=TOP);close.pack(side=RIGHT)

go.pack(side=TOP)


itemtitle.pack()


c1.pack(side=BOTTOM)


t1.pack(side=LEFT)


total.pack(side=LEFT)

scroll.pack(side=RIGHT,expand=1,fill=Y)


item.pack(side=LEFT,expand=0,fill= Y)


title4.pack()



#t1.pack()


window.mainloop()

加载中
0
聽雨人
聽雨人
难度太大,我做不了
0
不日小鸡
我不是高手,我是大神
0
J
JiaKlose

def delete()

     itemText = item.get(ACTIVE)

     item.delete(ACTIVE)

     解析价格,


此外你totle的计算还存在问题

totleValueText = total.get(1.0,END)

totleValue = 0

if totleValueText !='\n':

totleValue = int(totleValueText)


for row in iter(mycursor.fetchone, None):

     bar=row[0]

     name=row[1]

     des=row[2]

     pri=row[3]


      totleValue = totleValue + pri

      total.delete(1.0,END);

      total.insert(END,totleValue)

      item.insert(END,row)




0
enzozhong
enzozhong
这样看py代码好虐的感觉
返回顶部
顶部