The problem is that the '\ r' at the end clears the line you just printed, so what?
import time def show_Remaining_Time(time_delta): print("\r", end='') print('Time Remaining: %d' % time_delta, end='', flush=True) if __name__ == '__main__': count = 0 while True: show_Remaining_Time(count) count += 1 time.sleep(1)
Thus, first you clear the line, and then print the screen you want, keeping it on the screen for the entire time you sleep.
NOTE. The code above has been modified to add end='' , as indicated in the comments, for the code to work correctly on some platforms. Thanks to other readers for helping to develop a more complete answer.
source share