0

I can easily print a list of menu options vertically in the terminal like so:

menu = ["Option 1", "Option 2", "Option 3", "Option 4"]

for idx, element in enumerate(menu):
    y = 1 + idx
    x = 1

    stdscr.addstr(y, x, element)

This outputs the following in my current set-up:

Option 1
Option 2
Option 3
Option 4

But I am lost on how to do this horizontally. I've tried simply x = 1 + idx but that causes the output to be OOOOption 4, and I've tried a few variants. Does anyone have an idea of how I could achieve this? Thank you.

Sugardust
  • 35
  • 4

1 Answers1

0

What you need to do here is make a variable outside the loop which tells the x, y. Then in the x value has to be the old x value + len(element) + 1. So

menu = ["Option 1", "Option 2", "Option 3", "Option 4"]
y, x = 0, 0
for idx, element in enumerate(menu):
    stdscr.addstr(y, x, element)
    x = x + len(element) + 1

Hope i could help.

Toke-dk
  • 53
  • 7