Any way to clear python’s IDLE window?

Posted on

Question :

Any way to clear python’s IDLE window?

I know there’s a similar topic about python console, but I do not know if they are the same. I tried system(“clear”) and it didn’t work here.

How do I clear python’s IDLE window?

Answer #1:

The “cls” and “clear” are commands which will clear a terminal (ie a DOS prompt, or terminal window). From your screenshot, you are using the shell within IDLE, which won’t be affected by such things. Unfortunately, I don’t think there is a way to clear the screen in IDLE. The best you could do is to scroll the screen down lots of lines, eg:

print ("n" * 100)

Though you could put this in a function:

def cls(): print ("n" * 100)

And then call it when needed as cls()

Answered By: Brian

Answer #2:

os.system('clear') works on linux. If you are running windows try os.system('CLS') instead.

You need to import os first like this:

import os
Answered By: Nadia Alramli

Answer #3:

Most of the answers, here do clearing the DOS prompt screen, with clearing commands, which is not the question. Other answers here, were printing blank lines to show a clearing effect of the screen.

The simplest answer of this question is

It is not possible to clear python IDLE shell without some external module integration. If you really want to get a blank pure fresh shell just close the previous shell and run it again

Answered By: Abdul Rehman

Answer #4:

ctrl + L clears the screen on Ubuntu Linux.

Answered By: shxfee

Answer #5:

An extension for clearing the shell can be found in Issue6143 as a “feature request”. This extension is included with IdleX.

Answered By: Roger

Answer #6:

>>> import os

>>>def cls():
...    os.system("clear")
...
>>>cls()

That does is perfectly. No ‘0’ printed either.

Answered By: Derk Smith

Answer #7:

There does not appear to be a way to clear the IDLE ‘shell’ buffer.

Answered By: Mark Ribau

Answer #8:

The way to execute commands in Python 2.4+ is to use the subprocess module. You can use it in the same way that you use os.system.

import subprocess
subprocess.call("clear") # linux/mac
subprocess.call("cls", shell=True) # windows

If you’re executing this in the python console, you’ll need to do something to hide the return value (for either os.system or subprocess.call), like assigning it to a variable:

cls = subprocess.call("cls", shell=True)
Answered By: Rudd Zwolinski

Leave a Reply

Your email address will not be published.