#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Questioner's home
    Posts
    89
    Rep Power
    12

    How to code TImer like thing?


    How do I program those countdown timers? They print a number then immediately replace it with another number instead of printing 10 9 8 7 6 5... you get what I mean?

    Some similar thing is during loading or something, the system prints those "/" "-" "\" and "|" in the same place to simulate something's spinning, how do i do something like that?
    What can change the nature of a man?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Hi!

    Code:
    import sys
    import time
    
    signs = "/-\\|"
    while 1:
        for i in signs:
            sys.stdout.write("%s\r" % i)
            sys.stdout.flush()
            time.sleep(0.2)
    Regards, mawe
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Questioner's home
    Posts
    89
    Rep Power
    12
    Thanks Mawe that is very helpful!
    What can change the nature of a man?
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    620
    Rep Power
    65

    Red face


    mawe,

    mild problem here! Neither PythonWin nor IDLE interpret the \r correctly!

    The PythonWin IDE puts in a \n instead and IDLE puts in a goofy character.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Hi Dietrich!

    Well, idle prints \r here It seems that it doesn't know some of these escaped signs, like \r and \b.
    All I can say is what I always say: Don't use idle!
    Run it from the command line instead. (Sorry that I can't help you any better).

    Regards, mawe
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    well usually you have to run the script in the console then it works, the IDLE does not support them.
    Those people who think they know everything are a great annoyance to those of us who do.
  12. #7
  13. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    I've used \r in my editor (PythonWin and the Python IDLE) and it worked just fine.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    Code:
    def Count(X):
    	import os
    	while True:
    		if X == 0:
    			print str(1)
    			os.system("cls")
    			break
    		print str(X)
    		os.system("cls")
    		X -= 1
    I guess that works for the moment it only works in console like cmd windows
    Those people who think they know everything are a great annoyance to those of us who do.
  16. #9
  17. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    620
    Rep Power
    65

    Red face


    Originally Posted by †Yegg†
    I've used \r in my editor (PythonWin and the Python IDLE) and it worked just fine.
    Is there a config file for PythonWin somewhere? It might explain the difference. I had some other problems with PythonWin ever since I upgraded it from wxPython 2.3 to wxPython 2.4.
  18. #10
  19. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo