0

I'm practicing OOP on Python, but i would like to create a "loading screen" on python whichs prints:

>>>0%
>>>(_|_|_|_|_|_|_|_|_|_)
>>>Adding Oxygen...

#delete the last 3 lines and print*:

>>>1%
>>>(_|_|_|_|_|_|_|_|_|_)
>>>Adding Oxygen...

#delete the last 3 lines and print:

>>>2%
>>>(_|_|_|_|_|_|_|_|_|_)
>>>Adding Oxygen...

#repeat this until oxygen == 100% print:

>>>100%
>>>(■|■|■|■|■|■|■|■|■|■)
>>>Adding Oxygen...

Instead of:

0%
Adding oxygen...
1%
Adding oxygen...
2%
Adding oxygen...
3%
Adding oxygen...
4%
Adding oxygen...
5%
Adding oxygen...
6%
Adding oxygen...
7%
Adding oxygen...
8%
Adding oxygen...
9%
Adding oxygen...
(■|_|_|_|_|_|_|_|_|_)
10%

I tried to do this using "\r" but this deletes only the previous line and it doesn't work with this Should I use any kind of GUI library to make this posible?

What is the way to do this?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
josmanuel
  • 403
  • 1
  • 3
  • 10
  • 2
    Does this answer your question? [Rewrite multiple lines in the console](https://stackoverflow.com/questions/6840420/rewrite-multiple-lines-in-the-console) – mkrieger1 Dec 05 '20 at 18:54
  • There is [`tqdm`](https://github.com/tqdm/tqdm) for the progress bar. There is [`prompt-toolkit`](https://python-prompt-toolkit.readthedocs.io/en/stable/) for interactive CLI. – jfs Dec 05 '20 at 19:00

1 Answers1

0

To clear the shell screen from a Python script, you can use (after importing os)

os.system('cls||clear')

You can then rewrite your lines.

LeopardShark
  • 3,820
  • 2
  • 19
  • 33