Reputation: 1
I am trying to make a python program that writes the follwing to a terminal:
Frame 1 -- Loading Frame 2 -- Loading. Frame 3 -- Loading.. Frame 4 -- Loading... Frame 5 -- Loading
This would all be a function so that it repeats itself. The one problem I am having is that I have no idea how to reset the number of dots to zero after they equal three. My current code is below, any suggestions would be nice.
import pickle
import time
from sys import stdout
stdout.write("Loading")
def loaddot():
stdout.write(".")
time.sleep(.5)
loaddot()
loaddot()
Upvotes: 0
Views: 2056
Reputation: 49
You need to clear the screen, if you are on a linux system simply use the os library
import os
import time
while True:
for i in range(3):
print "Loading."<br>
time.sleep(3)<br>
os.system("clear")<br>
print "Loading.."<br>
time.sleep(3)<br>
os.system("clear")<br>
print "Loading..."<br>
time.sleep(3)<br>
os.system("clear")<br>
Upvotes: 0
Reputation: 4762
To do something like this, you really should be using the curses library. There exist several hacks to get the screen to clear, or backspace characters, but none compare to the UI features of curses:
http://docs.python.org/2.7/library/curses.html
Upvotes: 0
Reputation: 974
Here is my attempt:
import time
from sys import stdout
def loaddot():
stdout.write("."*(dots%3 + 1))
time.sleep(.5)
dots = 0
while(True):
dots += 1
stdout.write("Loading")
loaddot()
stdout.flush()
print
I believe there are better ways to do it in Python. I have not worked with the language that much, but this comes from what I know and my background in other languages.
Upvotes: 1