Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Curses: Returning to the Previous Menu
    primarykey
    data
    text
    <p>I have a menu system in ncurses. Choosing one of the options takes you to another menu. But how do I get back?</p> <pre><code>import curses def Main(): x = 0 while x!= ord('2'): x = screen.getch() screen.clear();screen.border(); screen.addstr(1,1, "Please choose:") screen.addstr(3,1, "1 - Another Menu") screen.addstr(4,1, "2 - Exit") if x==ord('1'): y = 0 while y!= ord('2'): y = screen.getch() screen.clear();screen.border(); screen.addstr(1,1, "Please choose from new menu:") screen.addstr(3,1, "1 - Do Something new") screen.addstr(4,1, "2 - Previous Menu") if y == ord('1'): doSomething() #Here I exit the internal loop. I need to go back to the previous menu, but I don't know how. ## ##exit outside loop and close program ## curses.endwin(); exit(); screen = curses.initscr() Main() </code></pre> <p>Ideally I'd need to use the GOTO module to jump between lines of code, but the device I'm using does not come with that module built-in.</p> <p>Do you guys know any other methods? Really appreciate any help.</p> <p>============ Update: ==================</p> <p>Okay, I also realized that you can regenerate both menu's with ease:</p> <pre><code>import curses def Main(): x = 0 while x!= ord('2'): #draws 1st menu screen.clear();screen.border(); screen.addstr(1,1, "Please choose:") screen.addstr(3,1, "1 - Another Menu") screen.addstr(4,1, "2 - Exit") x = screen.getch() #grab input AFTER first giving options :) if x==ord('1'): y = 0 z = 0 while y!= ord('2'): #draws 2nd menu screen.clear();screen.border(); screen.addstr(1,1, "Please choose from new menu:") screen.addstr(3,1, "1 - Do Something new") screen.addstr(4,1, "2 - Previous Menu") screen.addstr(6,1, "current loop : "+str(z)) y = screen.getch(); #grabs new input while z!= -1: #never breaks from loop unless 'break' is called if y == ord('1'): z += 1 break #regenerates 2nd menu break #regenerates 1st menu #Here we exit the internal loop. ## ##exit outside loop and close program curses.endwin(); exit(); screen = curses.initscr() Main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload