clear the screen

Discussion in 'Python' started by Yuanyuan Li, Apr 21, 2013.

  1. Yuanyuan Li

    Yuanyuan Li Guest

    How to clear the screen? For example, in the two player game. One player sets a number and the second player guesses the number. When the first playerenters the number, it should be cleared so that the second number is not able to see it. My question is how to clear the number.
    Thank you!
     
    Yuanyuan Li, Apr 21, 2013
    #1
    1. Advertising

  2. Yuanyuan Li

    Dave Angel Guest

    On 04/20/2013 10:45 PM, Yuanyuan Li wrote:
    > How to clear the screen? For example, in the two player game. One player sets a number and the second player guesses the number. When the first player enters the number, it should be cleared so that the second number is not able to see it. My question is how to clear the number.
    > Thank you!
    >


    Welcome to the python mailing list.

    The first thing you'd have to specify is your environment. Are you
    writing a gui program, and if so, with which toolkit (tk, wx, etc.).

    Or are you writing a console program? The simplest portable way is to
    issue 50 or so newlines, so things scroll beyond easy visibility. Of
    course, many terminal programs can easily scroll back, perhaps by using
    the mouse wheel.

    If you want something better than that, you'd have to specify your
    Python version and Operating System. Then somebody familiar with the
    quirks of that particular system can chime in.


    --
    DaveA
     
    Dave Angel, Apr 21, 2013
    #2
    1. Advertising

  3. On Sat, 20 Apr 2013 19:45:46 -0700, Yuanyuan Li wrote:

    > How to clear the screen? For example, in the two player game. One player
    > sets a number and the second player guesses the number. When the first
    > player enters the number, it should be cleared so that the second number
    > is not able to see it. My question is how to clear the number. Thank
    > you!



    What sort of screen? A GUI window, or in a terminal?

    If you have a GUI window, you will need to read the documentation for
    your GUI toolkit.

    If it is in a terminal, that will depend on the terminal. The best
    solution is to use Curses, if you can, but that is Unix only.

    Another solution is this:

    print("\x1b[H\x1b[2J")

    although that only works in some terminals, and it will not work in IDLE.


    Another solution is this:

    import os
    result = os.system("clear") # Linux, Mac, Unix

    or for Windows:

    result = os.system("cls")


    but again, it may not work in IDLE.


    Last but not least, if everything else fails, try printing a whole lot of
    blank lines:

    print("\n"*100)


    ought to do it on all but the tallest terminals, and amazingly, it even
    works in IDLE!



    --
    Steven
     
    Steven D'Aprano, Apr 21, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    Clear all fields on a screen

    tshad, May 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,312
    tshad
    May 20, 2005
  2. Boki
    Replies:
    5
    Views:
    11,744
    Darryl Pierce
    Apr 16, 2005
  3. owl
    Replies:
    2
    Views:
    903
  4. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,116
    Mark Fitzpatrick
    Jan 31, 2008
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    1,067
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page