Arrow Select Menu Help

So I am making a City Builder game that will be using an arrow select menu. My current one isn’t working.

Repl link:

import keyboard

def arrow_select(options):
    selection = 0

    while True:
        for i in range(len(options)):
            if selection == i:
                print(f"> {options[i]}")

        key_event = keyboard.read_event()
        if == 'down':
            selection = (selection + 1) % len(options)
        elif == 'up':
            selection = (selection - 1) % len(options)
        elif == 'enter':
            return options[selection]

import pyfiglet
from arrow_select import arrow_select

# Colors ->
BLACK = "\033[0;30m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
BROWN = "\033[0;33m"
BLUE = "\033[0;34m"
PURPLE = "\033[0;35m"
CYAN = "\033[0;36m"
LIGHT_GRAY = "\033[0;37m"
DARK_GRAY = "\033[1;30m"
LIGHT_RED = "\033[1;31m"
LIGHT_GREEN = "\033[1;32m"
YELLOW = "\033[1;33m"
LIGHT_BLUE = "\033[1;34m"
LIGHT_PURPLE = "\033[1;35m"
LIGHT_CYAN = "\033[1;36m"
WHITE = "\033[1;37m"
BOLD = "\033[1m"
FAINT = "\033[2m"
ITALIC = "\033[3m"
UNDERLINE = "\033[4m"
BLINK = "\033[5m"
NEGATIVE = "\033[7m"
CROSSED = "\033[9m"
END = "\033[0m"
# Background Colors ->
BACK_BLACK = "\u001b[40m"
BACK_RED = "\u001b[41m"
BACK_GREEN = "\u001b[42m"
BACK_YELLOW = "\u001b[43m"
BACK_BLUE = "\u001b[44m"
BACK_MAGENTA = "\u001b[45m"
BACK_CYAN = "\u001b[46m"
BACK_WHITE = "\u001b[47m"

def print_title():
  # ^ print a title
  PPC = "City Builder"
  ASCII = pyfiglet.figlet_format(PPC, font='big')
  print(GREEN + BOLD + ASCII + END)


options = ["Build", "Bank"]
1 Like

umm I’ve never used that but you can see this post it has I think exactly what you want but also a couple extra features (clears the screen every time, when you press a number it makes that selected, and it hides the cursor) you can remove those parts if you want

oh and to get the selected option as a string use menu()[1] to get option index use menu()[0]

@QwertyQwerty88 when I try to run it, it starts installing all of the things but it never finished. I let it run for 20+ minutes and it hasn’t worked, either Replit is being buggy or something else is happening.

are you on a crome book because that happens all the time right now im grounded so i don’t have my windows but when i was on windows it would always work

@AndrewMorris14 no I use an iPad

@QwertyQwerty88 I get an error of, ModuleNotFoundError: No module named cursor

Try installing it with pip?

@QwertyQwerty88 Could I do it where you type it in and it automatically goes there without pressing enter? I don’t think the arrow menu will work because I have waited a long time and when it tries to automatically add things it hasn’t.

Hello @SalladShooter, I’ve reviewed your code and made the necessary adjustments. Here’s the corrected version:

from typing import Iterable, Tuple
import curses

def menu(prompt: str, options: list) -> Tuple[int, str]:
    selected_option = 0
    curses.wrapper(draw_menu, prompt, options, selected_option)
    return selected_option, options[selected_option]

def draw_menu(stdscr, prompt: str, options: list, selected_option: int):
    stdscr.addstr(0, 0, prompt)

    while True:
        for i, option in enumerate(options):
            stdscr.addstr(2 + i, 2, f"{i + 1}. {option}", curses.A_BOLD if i == selected_option else curses.A_NORMAL)

        key = stdscr.getch()

        if key == curses.KEY_ENTER or key == 10:
        elif key == curses.KEY_UP and selected_option > 0:
            selected_option -= 1
        elif key == curses.KEY_DOWN and selected_option < len(options) - 1:
            selected_option += 1

prompt_text = "Choose an option:"
menu_options = ["Option 1", "Option 2", "Option 3"]

selected_index, selected_value = menu(prompt_text, menu_options)
print(f"You selected: {selected_value}")

Hey @Sky!

I haven’t been able to test Qwerty or your code because of the automatic installation when I click run. I have waited 20+ minutes but it never installs all the way therefore I can’t test anything.

1 Like

Strange, try and create a new Repl.

@Sky I have tried but they don’t work either.

1 Like

What exactly is happening, the Repl’s just won’t install the packages or?

@Sky it takes forever and doesn’t install them.

1 Like

You might have to make a bug report, I don’t think that is normal.

@Sky I already have Code Never Runs

1 Like