在Python 3.4.3中'TypeError:'函数'对象是不可订阅的'?

时间:2015-09-07 21:43:52

标签: 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.
    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,' Chips ',值...),通过访问词典Food_Stock和Food_Prices显示。它调用数据,然后应该显示它。这意味着它可以适应库存下降或上涨。

0 个答案:

没有答案