tkinter - Python says I don't have attribute when I do -


this question has answer here:

so i'm pretty new coding , i'm trying make simple menu program tkinter let user click on food items , display his/her total.

when run program python says attributeerror: 'menu' object has no attribute 'potato_skins'. when take out "potato skins" says not have attribute of bread, , on , forth.

can please me, here code:

#order up! #restaurant menu lets user pick foods, show overall price  tkinter import *  class menu(frame):     """menu let's user choose food , shows total price."""      def __init__(self, master):         """initialize frame"""         super(menu, self).__init__(master)         self.grid()         self.menu_widgets()      def menu_widgets(self):         """create menu items."""          #appetizer label         label(self,               text = "choose appetizers:"               ).grid(row = 0, column = 0, sticky = w)         #appetizer checkbuttons         self.motzerella_sticks = booleanvar()         checkbutton(self,                     text = "mozzerella sticks, $5",                     variable = self.motzerella_sticks,                     command = self.update_total()                     ).grid(row = 1, column = 1, sticky = w)         self.potato_skins = booleanvar()         checkbutton(self,                     text = "potato skins, $7",                     variable = self.potato_skins,                     command = self.update_total()                     ).grid(row = 1, column = 1, sticky = w)         self.bread = booleanvar()         checkbutton(self,                     text = "bread, $0",                     variable = self.bread,                     command = self.update_total()                     ).grid(row = 1, column = 2, sticky = w)          #entree label         label(self,               text = "pick entree:"               ).grid(row = 2, column = 0, sticky = w)         #entree checkbuttons         self.chicken = booleanvar()         checkbutton(self,                     text = "chicken , brocolli, $10",                     variable = self.chicken,                     command = self.update_total()                     ).grid(row = 3, column = 0, sticky = w)         self.soup = booleanvar()         checkbutton(self,                     text = "brocolli cheddar soup, $12",                     variable = self.soup,                     command = self.update_total()                     ).grid(row = 3, column = 1, sticky = w)         self.pasta = booleanvar()         checkbutton(self,                     text = "alfredo pasta, $15",                     variable = self.pasta,                     command = self.update_total()                     ).grid(row = 3, column = 2, sticky = w)          #dessert label         label(self,               text = "choose dessert:"               ).grid(row = 4, column = 0, sticky = w)         #dessert checkbuttons         self.cake = booleanvar()         checkbutton(self,                     text = "chocolate cake, $15",                     variable = self.cake,                     command = self.update_total()                     ).grid(row = 5, column = 0, sticky = w)         self.brownie = booleanvar()         checkbutton(self,                     text = "brownies, $13",                     variable = self.brownie,                     command = self.update_total()                     ).grid(row = 5, column = 1, sticky = w)          #create text box display total         self.total_txt = text(self, width = 40, height = 5, wrap = word)         self.total_txt.grid(row = 6, column = 0, columnspan = 2, sticky = w)      def update_total(self):         """show total"""         total = 0          if self.motzerella_sticks.get():             total += 5          if self.potato_skins.get():             total += 7          if self.bread.get():             total += 0          if self.chicken.get():             total += 10          if self.soup.get():             total += 12          if self.pasta.get():             total += 15          if self.cake.get():             total += 15          if self.brownie.get():             total += 13          self.total_txt.delete(0.0, end)         self.total_txt.insert(0.0, "your total is: ", total)  #main root = tk() root.title("menu") app = menu(root) root.mainloop() 

the reason execute function instead of passing command parameter.

command = self.update_total() 

this means executed when creating checkbutton associated self.motzerella_sticks. @ point self.potato_skins not exist.

to fix it, pass function, rather executing it.

command = self.update_total 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -