0
私はかなり新しいコーディングです。私はtkinter
で簡単なメニュープログラムを作って、ユーザーが特定の食品アイテムをクリックさせ、 /彼女の合計。Pythonは私が属性を持っていないと言っています
プログラムを実行すると、pythonはAttributeError: 'Menu' object has no attribute 'potato_skins'
と表示されます。私が「ジャガイモの皮」を取り出したとき、私はパンの属性などを持っていないと言っています。
#Order Up!
#restaurant menu that lets the user pick foods, then show overall price
from tkinter import *
class Menu(Frame):
"""Menu that let's the user choose food and shows the total price."""
def __init__(self, master):
"""Initialize the frame"""
super(Menu, self).__init__(master)
self.grid()
self.menu_widgets()
def menu_widgets(self):
"""Create all the menu items."""
#Appetizer Label
Label(self,
text = "Choose your 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 your entree:"
).grid(row = 2, column = 0, sticky = W)
#Entree Checkbuttons
self.chicken = BooleanVar()
Checkbutton(self,
text = "chicken and 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 your 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 a Text box to 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 the 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()
状況が壊れている行を示す完全なトレースバックを提供すると便利です –