';类型错误:';功能';对象不可下标';在Python 3.4.3中?
我有一份食物菜单,存货和价格在不同的字典里 食品库存:';类型错误:';功能';对象不可下标';在Python 3.4.3中?,python,typeerror,Python,Typeerror,我有一份食物菜单,存货和价格在不同的字典里 食品库存: Food_Stock = { 'Chips' : 15, 'Bagels' : 27, 'Cookies' : 25}#Food Stock. 食品价格: Food_Prices = {#Food Prices. 'Chips' : 1, 'Bagels' : 0.5, 'Cookies' : 0.4} 食物菜单: def Food_Menu():#The food menu. T
Food_Stock = {
'Chips' : 15,
'Bagels' : 27,
'Cookies' : 25}#Food Stock.
食品价格:
Food_Prices = {#Food Prices.
'Chips' : 1,
'Bagels' : 0.5,
'Cookies' : 0.4}
食物菜单:
def Food_Menu():#The food menu.
Top_Frame = Frame(root)
Top_Frame.pack()
Bottom_Frame = Frame(root)
Bottom_Frame.pack(side = BOTTOM)
tree['columns'] = ('Price', 'Qty', 'Print Receipt')#additional columns after the default '#0'
tree.column('Price', stretch = 0, width = 100, anchor = E)#Price Column, tkinter.E aligns contents to the "east"
tree.column('Qty', stretch = 0, width = 100, anchor = E)#Quantity Column
tree.column('Print Receipt', stretch = 0, width = 100, anchor = E)#Print Receipt Column
tree.heading('#0', text = "Item")# default column responsible for tree mechanics
tree.heading('Price', text = "£")
tree.heading('Qty', text = "Quantity")
tree.insert('', 0, '_Chips_', values = (Food_Prices['Chips'], Food_Stock['Chips']), text = "Chips")#Parent, text goes to '#0', values go to tree['columns']
tree.insert('_Chips_', 0, text = "Add to Order")#Child
tree.insert('', 1, '_Bagels_', text = "Bagels", values = (Food_Prices['Bagels'], Food_Stock['Bagels']))#Parent.
tree.insert('_Bagels_', 1, Add_Food_Item_To_Order_Button(), text = "Add to Order")#Child
tree.insert('', 2, '_Cookies_', text = "Cookies", values = (Food_Prices['Cookies'], Food_Stock['Cookies']))#Parent.
tree.insert('_Cookies_', 2, Add_Food_Item_To_Order_Button(), text = "Add to Order")#Child
tree.pack()
GUI通过将其链接到字典来显示股票和价格,如果可行的话,它应该显示
错误消息:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Users\liam\Documents\BOA\Coursework\Python - Mr Naeem\Comp 4 Practical Project\Bar System.py", line 56, in Food_Button
Food_Menu()
File "C:\Users\liam\Documents\BOA\Coursework\Python - Mr Naeem\Comp 4 Practical Project\Bar System.py", line 103, in Food_Menu
tree.insert('', 0, '_Chips_', values = (Food_Prices['Chips'], Food_Stock['Chips']), text = "Chips")#Parent, text goes to '#0', values go to tree['columns']
TypeError: 'function' object is not subscriptable
阐述:
GUI将显示一个食品菜单-def food_menu-有三列,“价格”、“数量”和“打印收据”
然后是树,例如tree.insert(“”,0,'芯片',值…),通过访问字典食品库存和食品价格来显示。它调用数据,然后显示它。这意味着它可以根据股票的下跌或上涨进行调整。
'function'对象不可下标
表示您正在执行以下操作:
def foo(): pass
something = foo[1]
这意味着食品价格
或食品库存
实际上是一个函数,而不是一个变量。通过在导致错误的行之前添加简单的print语句,应该可以很容易地确定是哪一行
print(Food_Prices, Food_Stock)
这很可能是因为您的代码中有一个名为
食品价格
或食品库存
的函数,或者您重新分配了其中一个变量的值 哪一行出错?此处缺少代码的关键部分。您已经从错误消息中删除了所有特定信息,并且您只向我们展示了一个函数(尚未订阅)。我认为我在主体部分很清楚,但我将详细说明并发布错误消息。