Python Forum
Help Returning to Different Menus
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Returning to Different Menus
#2
(May-07-2022, 12:45 AM)Extra Wrote: How can I make it so depending on who is logged in (StanadardUser or Admin/SuperUser) it returns to the appropriate Menu?
The way you made it you do not return to a menu, instead you start a new menu because you end most of your functions with adminMenu(). You should end the function just with "return" and make the menu repeating. Also you have the printing of the menu separated from inputting the choice. That makes it more difficult. Also you are using "exit()" to end the program. This is not needed when you just use "return".
A small example of what I mean:
def adminMenu():
    while True:    # Keep showing the menu until user wants to quit.
        print('=============================')
        print('= Inventory Admin Menu =')
        print('=============================')
        print('(1) Add New Item to Inventory')
        print('(2) Delete Item from Inventory')
        print('(3) Update Inventory')
        print('(4) Search Item in Inventory')
        print('(5) Print Inventory Report')
        print('(Q) Quit')
        CHOICE = input("Enter choice: ")
        if CHOICE == '1':
            addInventory()
        elif CHOICE == '2':
            removeInventory()
        elif CHOICE == '3':
            updateInventory()
        elif CHOICE == '4':
            searchInventory()
        elif CHOICE == '5':
            printInventory()
        elif CHOICE == 'q' or CHOICE == 'Q':
            break    # Stop repeating the menu.
    return    # Return to the previous level
#---------------------------------------------------------------
def addInventory():
    #Connect to the inventory database (inventory.db)
    connection = sqlite3.connect("inventory.db")
    cursor = connection.cursor()
  
    cursor = connection.cursor()
 
    cursor.execute('''
        insert into items (name, quantity, price, sell_price, description, category, location)
        values (?,?,?,?,?,?,?)
        ''', inserts())
    connection.commit()
 
    #Close the connection
    connection.close()
    # adminMenu()    # Don't do this.
    return    # Return to the calling menu.
Reply


Messages In This Thread
Help Returning to Different Menus - by Extra - May-07-2022, 12:45 AM
RE: Help Returning to Different Menus - by ibreeden - May-08-2022, 10:54 AM
RE: Help Returning to Different Menus - by Extra - May-09-2022, 10:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  installing anaconda3 fails (failed to create menus) Hikki 9 4,534 Feb-10-2022, 06:49 PM
Last Post: snippsat
  Contextual pop-up menus in Sublime Text Mondata 4 2,606 Apr-08-2020, 06:32 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020