TypeError: Menu() missing 1 required positional argument: 'self'
I have put self.Menu() in init class and still has error, i have tried to also put self.Menu = Menu() and same error issue. i need to use self in the Menu to call the other classes eg. self.addProductsToDB()
class SupermarketDAO:
def __init__(self):
self.count = None
self.option = None
self.barcode = None
self.cursor = None # code to get cursor from db
self.dbCreated = False
_continue = True
self.Menu()
self.startUp()
# menu to ask user what option they would like to choose
def Menu(self):
print("[1] Add products to Database")
print("[2] List all products in Database, based on product bar-code")
print("[3] List all transactions(Ascending order of date of transaction")
print("[4] Display Barchart of Products sold by quantity")
print("[5] Display an Excel report of all transactions")
print("[6] EXIT")
option = int(input("Enter your option:"))
while option != 0:
if option == 1:
print("go to Add products to Database")
self.addProductToDB(products)
break
elif option == 2:
print("go to List all products in Database")
self.listAllProducts()
break
elif option == 3:
print("go to List all transactions")
self.listAllTransactions()
break
elif option == 4:
print("go to Display Barchart of Products sold by quantity")
self.displayBarchartOfProductsSold()
break
elif option == 5:
print("go to Display an Excel report of all transactions")
self.addProductToDB(products)
break
elif option == 6:
print("EXIT")
sys.exit()
else:
print("invalid option!") # if no option is chosen print invalid prompt user again to type.
break
Menu()
To call the methods of a class, you have to create an object of that class first.
So in the end, instead of doing Menu()
supermarket = SupermarketDAO()
supermarket.Menu()