Mar-17-2019, 09:49 AM
Hi, I'am new to Python - I was practicing some coding and got into error:AttributeError: 'ResturantUI' object has no attribute 'resturant'
Here's the code:
Entry(text=self.resturant.__str__(self)).grid(row=2,column=1,columnspan=3,sticky=W)
AttributeError: 'ResturantUI' object has no attribute 'resturant'
Here's the code:
from tkinter import * from chapter9 import resturant class ResturantUI(Frame): def __init__(self,master): super(ResturantUI, self).__init__(master) self.grid() self.create_widget() self.resturant = resturant.Resturant('item1',2) self.resturant.add_item('item2',3) def create_widget(self): Label(self,text="ResturantUI").grid(row=0,column=0,columnspan=1,sticky=W) Label(text="Here's the menu!...").grid(row=1,column=0,columnspan=3,sticky=W) Entry(text=self.resturant.__str__(self)).grid(row=2,column=1,columnspan=3,sticky=W) root = Tk() root.title('REsturantUI') root.geometry('200x100') app = ResturantUI(root) root.mainloop()# Following is the code of resturant
class Resturant(): def __init__(self,item,price): # dictionary to store item and price self.d = {} self.item = item self.price = price self.d[item] = price def __str__(self): rep = "" if self.d.items(): for item in self.d.keys(): rep += item +':\t'+str(self.d[item])+'\n' if self.total: rep += 'Your bill is: '+str(self.total) return rep else: rep = "<EMPTY>" return rep def add_item(self,item,price): self.d.__setitem__(item,price) def remove_item(self,item): if self.d.__contains__(item): self.d.pop(item) @property def total(self): amount = 0 for k in self.d.keys(): amount += self.d.get(k) return amountTHIS IS THE ERROR AM FACING..
Entry(text=self.resturant.__str__(self)).grid(row=2,column=1,columnspan=3,sticky=W)
AttributeError: 'ResturantUI' object has no attribute 'resturant'