Question
python please help I need help trying to convert this code into a GUI-based program. code to copy class item: def __init__(self,name,wholesale,retail,no_of_times): self.name=name self.wholesale=wholesale self.retail=retail
python please help
I need help trying to convert this code into a GUI-based program.
code to copy
class item: def __init__(self,name,wholesale,retail,no_of_times): self.name=name self.wholesale=wholesale self.retail=retail self.no_of_times=no_of_times def __str__(self): return f"{self.name} {self.wholesale} {self.retail} {self.no_of_times}"
'''function to print the menu to restaurant manager ''' def print_menu(menu): for index, i in enumerate(menu, start=1): print(f"{index}. {i}") '''function to print the menu to customer''' def customer_menu(menu): for index, i in enumerate(menu, start=1): print(f"{index}. {i.name} {i.retail}") ''' Function to search for a item in menu with the given name''' def search(menu,name): for i in range(len(menu)): if menu[i].name==name.strip(): return i print(menu[i].name+" "+name) print("Item not present in menu") return -1 ''' Function to place order by the customer''' def place_order(menu): names=[] quantity=[] total=0 while 1: print("Enter choice") ch=int(input()) print("Enter Quantity") q=int(input()) menu[ch-1].no_of_times+=q total+=(menu[ch-1].retail*q) names.append(menu[ch-1].name) quantity.append(q) print("Do you want to place more order 1) yes 2) no") con=int(input()) if con==2: break ''' 5% tax on the total amount''' total += total*0.05 print("Add Tip") tip=int(input()) ''' Adding tip to the total ''' total+=tip ''' printing bill of the customer ''' print("\t\tBILL ")
for name,q in zip(names,quantity): print(f"{name} {q}") print("Total Bill is "+str(total)) return menu ''' Function to remove item from the menu''' def removeItem(menu,name): index=search(menu,name) print(f"{menu[index].name} Deleted From menu") menu=menu[:index]+menu[index+1:] return menu ''' function to add item in the menu''' def addItem(menu): print("Enter name") name=input() print("Enter wholesale price") wholesale=int(input()) print("Enter retail price") retail= int(input()) print("Number of items") no_of_times=int(input()) menu.append(item(name,wholesale,retail,no_of_times)) ''' Function to print the update menu''' def update_menu(): print("Enter choice to update") print("1) Name") print("2) wholesale") print("3) Retail") print("4) No of Items") ''' Function to update item in the menu''' def updateitem(menu,name): index=search(menu,name) update_menu() ch=int(input()) if ch==1: print("Enter new name") name=input() menu[index].name=name elif ch==2: print("Enter new wholsale price") wholesale=int(input()) menu[index].wholesale=wholesale elif ch==3: print("Enter new retail price") retail=int(input()) menu[index].retail=retail elif ch==4: print("Enter new number of items") no=int(input()) menu[index].no_of_times=no return menu ''' Function to print the main menu''' def Menu(): print("*************MENU********") print("1 . Restaurant Manager") print("2 . Customer") ''' Function to print the restaurent manager display''' def restaurent_manager_menu(): print("Restaurant Manager Menu") print("1. Add Item") print("2. Delete Item") print("3. Update Item") print("4. Print Menu") ''' Function to write the updated menu in the file''' def write_to_file(menu): with open("menu", "w") as f: for i in menu: f.write(f"{i.name},{i.wholesale},{i.retail},{i.no_of_times} ")
if __name__=="__main__": ''' array to store list of items ''' menu=[] ''' reading items from file into list''' with open("menu") as f:
for line in f.readlines(): arr=line.rstrip().split(',') menu.append(item(arr[0],int(arr[1]),int(arr[2]),int(arr[3]))) ''' While the user does not exit keep looping''' while 1: ''' display the main menu ''' Menu() ''' Enter choice ''' ch1=int(input()) ''' if choice is 1 print restaurent manager display''' if ch1==1: restaurent_manager_menu() ''' Enter choice ''' ch2=int(input()) if ch2==1: ''' add item in the menu''' addItem(menu) elif ch2==2: ''' if choice is 2 remove a item ''' print("Enter name of dish to remove ") name=input() menu=removeItem(menu,name) elif ch2==3: ''' if choice is 3 update the item''' print("Enter name of item to update") name=input() menu=updateitem(menu,name) elif ch2==4: ''' if choice is 4 print the menu''' print_menu(menu) else:
print("*****Customer's Menu******") print("1. View Menu") print("2. Place Order") ch=int(input())
if ch==1: '''Display customers menu''' customer_menu(menu) elif ch==2: ''' invoke place order menu ''' menu=place_order(menu)
print("1. To Continue 2.Exit") ch=int(input()) ''' if choice is 2 exit ''' if ch==2: break '''Store the updated menu into the file menu ''' write_to_file("menu",menu)
Menu.txt
Ham and Egg Sandwich $15.75 Bacon and Cheese Plate $9.50 Tuna Salad $12.30 Beef Soup $9.00 Spicy Beef Barbeque $20.00 Pork Barbeque $18.00 Oven Chicken Barbeque $15.00 Pulled Beef Barbeque Burger $25.00 House Salad $5.00 Pellegrino $5.40 White Wine $7.50 Red Wine $11.00 Hot dog $7.00 Chips $10.00 Noodles $20.50 Ribeye $27.50 Salad $14.00 Beer $14.50 Sour Dough Bread $15.50 Cheese $30.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started