Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43983 > unrolled thread

clear the screen

Started byYuanyuan Li <xintai404@gmail.com>
First post2013-04-20 19:45 -0700
Last post2013-04-21 12:49 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  clear the screen Yuanyuan Li <xintai404@gmail.com> - 2013-04-20 19:45 -0700
    Re: clear the screen Dave Angel <davea@davea.name> - 2013-04-21 06:21 -0400
    Re: clear the screen Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-21 12:49 +0000

#43983 — clear the screen

FromYuanyuan Li <xintai404@gmail.com>
Date2013-04-20 19:45 -0700
Subjectclear the screen
Message-ID<7aecbd4f-192e-43f2-99fb-f55c93701841@googlegroups.com>
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!

[toc] | [next] | [standalone]


#43995

FromDave Angel <davea@davea.name>
Date2013-04-21 06:21 -0400
Message-ID<mailman.874.1366539710.3114.python-list@python.org>
In reply to#43983
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

[toc] | [prev] | [next] | [standalone]


#44000

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-04-21 12:49 +0000
Message-ID<5173e05f$0$29977$c3e8da3$5496439d@news.astraweb.com>
In reply to#43983
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web