0
import threading
def bananas():
    threading.Timer(1,bananas).start()
    money += bananaPrice
while True:
    print(money)
    print(f"[1] Upgrade Bananas: {bananaUpgrade}")
    o = int(input("> "))

How do I keep updating the "money" variable as it increases while staying in the input without being glitchy while running?

Edit: I am currently using os.system("cls")

w1ndnd
  • 45
  • 5

1 Answers1

0

Sounds so simple, and yet it's so complicated!

Terminals are not designed to have parts of them refreshed, much less while accepting input. Even so, it's possible and widely done.

How? ANSI escape codes!

The idea is to move the cursor to location where you display the data which needs to be updated and write it there.

Here's an example of how to use them: https://stackoverflow.com/a/64222858/4088472

The second challenge is printing while waiting for an input. This is tricky because python has traditionally been a single-threaded, synchronous language while what you're looking for is an async input.

Take a look at this question: https://stackoverflow.com/a/58461085/4088472

Slava Knyazev
  • 5,377
  • 1
  • 22
  • 43