I have a food menu and the stock and prices are in separate dictionaries.
Food Stock:
Food_Stock = {
'Chips' : 15,
'Bagels' : 27,
'Cookies' : 25}#Food Stock.
Food Prices:
Food_Prices = {#Food Prices.
'Chips' : 1,
'Bagels' : 0.5,
'Cookies' : 0.4}
Food Menu:
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()
The GUI displays the stock and price by linking it to the dictionary, or it should if it worked.
The error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:Python34lib kinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:UsersliamDocumentsBOACourseworkPython - Mr NaeemComp 4 Practical ProjectBar System.py", line 56, in Food_Button
Food_Menu()
File "C:UsersliamDocumentsBOACourseworkPython - Mr NaeemComp 4 Practical ProjectBar 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
Elaboration:
The GUI will display a food menu - def Food_Menu - which has three columns, 'Price', 'Quantity' and 'Print Receipt'.
Then there are trees e.g tree.insert("", 0, 'Chips', values...) that are displayed by accessing the dictionaries Food_Stock and Food_Prices. It calls the data, then is supposed to display it. This means it can adjust to the stock going down or up.
See Question&Answers more detail:
os