<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<font face="Franklin Gothic Medium"><br id="ecxFontBreak">I'm coding a GUI program which presents the user with a resteraunt menu, and allows them to choose how much of each item they want to purchase before ordering. Here is my code:<BR> <BR>#Order up GUI program<br>#User is presented with a simple resturaunt menu<br>#They then select the items they want to order and then they are presented with the total bill<BR>from tkinter import *<BR>class Application(Frame):<br> """Based on the frame class, the application widget holds all other widgets. """<br> def __init__(self,master):<br> """Initialise the frame. """<br> super(Application,self).__init__(master)<br> self.grid()<br> self.create_widgets()<br> self.total=0<br> <br> self.spag_ent_check=True<br> self.tater_ent_check=True<br> self.soup_ent_check=True<br> self.fish_ent_check=True<BR> self.spag_cost=5.15<br> self.tater_cost=4.70<br> self.soup_cost=4.20<br> self.fish_cost=5.95<BR> def create_widgets(self):<br> """Create all of the widgets in the program. """<br> Label(self,text="Select the items you want to order:").grid(row=0,column=0,sticky=W)<br> Label(self,text="Quantity:").grid(row=0,column=0,sticky=E)<BR> Label(self,text="Spaghetti Bolognese (5.15)").grid(row=1,column=0,sticky=W)<br> self.spag_ent=Entry(self)<br> self.spag_ent.grid(row=1,column=0,sticky=E)<BR> Label(self,text="Potato Salad (4.70)").grid(row=2,column=0,sticky=W)<br> self.tater_ent=Entry(self)<br> self.tater_ent.grid(row=2,column=0,sticky=E)<BR> Label(self,text="Chicken Soup (4.20)").grid(row=3,column=0,sticky=W)<br> self.soup_ent=Entry(self)<br> self.soup_ent.grid(row=3,column=0,sticky=E)<BR> Label(self,text="Smoked Salmon (5.95)").grid(row=4,column=0,sticky=W)<br> self.fish_ent=Entry(self)<br> self.fish_ent.grid(row=4,column=0,sticky=E)<BR> Label(self,text="Total Bill:").grid(row=7,column=0,sticky=W)<br> self.bill_txt=Text(self,height=10,wrap=WORD)<br> self.bill_txt.grid(row=8,column=0,sticky=W)<BR> Button(self,text="Order Up!",command=self.calc_total).grid(row=5,column=0,sticky=W)<BR> def calc_total(self):<br> """Update the text widget if they order Spaghetti Bolognese. """<br> try:<br> int(spag_ent.get())<br> except:<br> message="You have to enter a number in the quantity box. \n"<br> self.bill_txt.delete(0.0,END)<br> self.bill_txt.insert(0.0,message)<br> self.spag_ent_check=False # set to False if user enters anything other than an integer in the entry widget<BR> if self.spag_ent_check:<br> spag_quant=self.spag_ent.get()<br> spag_total=self.spag_cost*spag_quant<br> self.total+=spag_total<BR> try:<br> int(tater_ent.get())<br> except:<br> message="You have to enter a number in the quantity box. \n"<br> self.bill_txt.delete(0.0,END)<br> self.bill_txt.insert(0.0,message)<br> self.tater_ent_check=False # set to False if user enters anything other than an integer in the entry widget<BR> if self.tater_ent_check:<br> tater_quant=self.tater_ent.get()<br> tater_total=self.tater_cost*tater_quant<br> self.total+=tater_total<BR> try:<br> int(soup_ent.get())<br> except:<br> message="You have to enter a number in the quantity box. \n"<br> self.bill_txt.delete(0.0,END)<br> self.bill_txt.insert(0.0,message)<br> self.soup_ent_check=False # set to False if user enters anything other than an integer in the entry widget<BR> if self.soup_ent_check:<br> soup_quant=self.soup_ent.get()<br> soup_total=self.soup_cost*soup_quant<br> self.total+=soup_total<BR> try:<br> int(fish_ent.get())<br> except:<br> message="You have to enter a number in the quantity box. \n"<br> self.bill_txt.delete(0.0,END)<br> self.bill_txt.insert(0.0,message)<br> self.fish_ent_check=False # set to False if user enters anything other than an integer in the entry widget<BR> if self.fish_ent_check:<br> fish_quant=self.fish_ent.get()<br> fish_total=self.fish_cost*fish_quant<br> self.total+=fish_total<br> <br> self.bill_txt.delete(0.0,END)<br> self.bill_txt.insert(0.0,self.total)<BR>#main<br>root=Tk()<br>root.title("Order Up!")<br>app=Application(root)<br>root.mainloop()<BR> <br>The 'calc_total' function is supposed to calculate the users bill and then display it in the text widget, but every time I try it, it comes up as 0. Can anyone help me? <BR> <BR>Thanks in advance,<BR>Myles Broomes</font><BR> </div></body>
</html>