0

This just keeps freezing. The while loop does not run and I think that's the problem

from Tkinter import*

def reveal():
    counter=0
    lowest=0
    Stotal=0
    i=0

    cost=float(cost_ent.get())
    if cost>0:
        lowest=cost
        counter+=1
        Stotal=cost+Stotal
    else:
        message="Invalid Number"
        txt.insert(0.0, message)
    while i==0:
        cost=float(cost_ent.get())
        if cost>0:
            counter+=1
            Stotal=cost+Stotal
            if cost<lowest:
                lowest=cost
        else:
            message="Invalid Number"
            txt.insert(0.0, message)

    message="The number of items:",counter,"\n"
    txt.insert (0.0, message)
    message="The subtotal is:",Stotal,"\n"
    txt.insert(0.0, message)
    message="The lowest item is:",lowest,"\n"
    txt.insert(0.0, message)
    message="The discount is:", discount,"\n"
    txt.insert(0.0, message)
    message="Before tax:", Stotal-discount,"\n"
    txt.insert(0.0, message)
    tax=Stotal*tax
    message="The tax is:",tax,"\n"
    txt.insert(0.0, message)
    message="The total is:",Stotal+tax,"\n"
    txt.insert(0.0, message)


    txt.delete(0.0, END)
root=Tk()
root.title("BOXING DAY SALE !!!!!!")
root.geometry("600x400")
app=Frame(root)
app.grid()

instl_lbl=Label(app,text = "Enter item cost")
instl_lbl.grid(row=1, column=1, sticky=W)
cost_ent=Entry(app)
cost_ent.grid(row=1, column=2, sticky=W)

bttn=Button(app, text="Enter", command=reveal)
bttn.grid(row=2, column=2, sticky=W)


txt=Text (app, width=50, height=10, wrap=WORD)
txt.grid(row=4, column=2, sticky=W)


root.mainloop()
2
  • Where is your variable "i" of the while loop changing its value? to something other than 0 ? Commented Dec 20, 2012 at 12:26
  • You cannot have a while loop in your tkinter application. The mainloop is a loop itself. This means that every time you run your while loop, the mainloop is paused until your loop is finished. Commented Dec 21, 2012 at 22:02

1 Answer 1

2

This code is the problem:

while i==0:
    cost=float(cost_ent.get())
    if cost>0:
        counter+=1
        Stotal=cost+Stotal
        if cost<lowest:
            lowest=cost
    else:
        message="Invalid Number"
        txt.insert(0.0, message)

i is never changed. It will always be zero, so the loop never terminates.

(you also have a bug in that you're using 0.0 as the starting index, but tkinter text indexes should be strings, and the line numbers start counting at one, not zero.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.