loading screen python

Solutions on MaxInterview for loading screen python by the best coders in the world

showing results for - "loading screen python"
Salvatore
18 Oct 2018
1import sys
2import time
3print("pls wait", end ="")
4loading = True  # a simple var to keep the loading status
5loading_speed = 4  # number of characters to print out per second
6loading_string = "." * 6  # characters to print out one by one (6 dots in this example)
7while loading:
8    for index, char in enumerate(loading_string):
9        # you can check your loading status here
10        # if the loading is done set `loading` to false and break
11        sys.stdout.write(char)  # write the next char to STDOUT
12        sys.stdout.flush()  # flush the output
13        time.sleep(1.0 / loading_speed)  # wait to match our speed
14    index += 1  # lists are zero indexed, we need to increase by one for the accurate count
15    # backtrack the written characters, overwrite them with space, backtrack again:
16    sys.stdout.write("\b" * index + " " * index + "\b" * index)
17    sys.stdout.flush()  # flush the output