在Python中将数量按钮显示在适当位置的问题

时间:2018-02-15 09:37:41

标签: python-3.x

我正在使用Python构建一个页面,它有2个框架,一个框架用于显示产品,当我们点击产品时,它应该执行mouseclickevent并应显示在第二个框架中。与产品名称一起,它应显示数量+和 - 选项以递增和递减。

我正在使用pycharm professional 2017.3.2

这是我的代码:

def OnDoubleClick(event):
    a = tree.selection()[0]
    price = tree.item(a, "values")
    amt = price[1]
    print("amt is :",amt)

    t1=0

    v1 = IntVar(receiptbox, value='1')

    def onMinus():
        if (v1.get()>0):
            v1.set(v1.get() - 1)

    btn1 = Button(receiptbox, justify=CENTER, text="-
",command=onMinus,bg="#33ccff")
    receiptbox.insert(END, "\n")
    btn1.pack(side=LEFT,anchor=E)


    e1 = Entry(receiptbox, justify=CENTER, textvariable=v1, width=4, state="readonly")
    e1.pack(side=LEFT,anchor=E)

    def onPlus():
        v1.set(v1.get() + 1)
# receiptbox.delete("1.0", END)
        if(v1.get()>1):
            receiptbox.delete("1.0", END)
# v1.set(v1.get() + 1)
            var = v1.get()
            price = tree.item(a, "values")
            amt1 = (price[1])
# amt2 = int(amt1)

# t1 = float(amt1) * (var)
            receiptbox.insert(END, tree.item(a, "text") + " Sub Total: "+str(float(amt1) * (var)))
            receiptbox.insert(END,"\n")


    btn2 = Button(receiptbox, justify=CENTER, text="+", command=onPlus,bg="#33ccff")
    btn2.pack(side=LEFT,anchor=E)

    receiptbox.insert(END,"\n")

    if (v1.get()==1):
        total = (v1.get() * amt)
        print("Total is :"+str(total))
        receiptbox.insert(END, tree.item(a, "text") + " Sub Total: " + str(total))
        receiptbox.insert(END, "\n")
        receiptbox.insert(END, "\n\n")

我能够显示产品列表并且鼠标点击工作正常。产品从数据库中列出。问题在于数量按钮。它没有进入正确的位置。我的意思是它应该与产品名称一起显示在同一行中。

0 个答案:

没有答案