Any way to clear python's IDLE window?

2019-01-04 17:05发布

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?

24条回答
SAY GOODBYE
2楼-- · 2019-01-04 17:27

If you are using the terminal ( i am using ubuntu ) , then just use the combination of CTRL+l from keyboard to clear the python script, even it clears the terminal script...

查看更多
We Are One
3楼-- · 2019-01-04 17:28

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()

查看更多
该账号已被封号
4楼-- · 2019-01-04 17:28

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

查看更多
祖国的老花朵
5楼-- · 2019-01-04 17:28

There is no need to write your own function to do this! Python has a built in clear function.

Type the following in the command prompt:

shell.clear()
查看更多
The star\"
6楼-- · 2019-01-04 17:32

You can make an AutoHotKey script.

To set ctrl-r to a hotkey to clear the shell:

^r::SendInput print '\n' * 50 {Enter}

Just install AutoHotKey, put the above in a file called idle_clear.ahk, run the file, and your hotkey is active.

查看更多
beautiful°
7楼-- · 2019-01-04 17:33

As mark.ribau said, it seems that there is no way to clear the Text widget in idle. One should edit the EditorWindow.py module and add a method and a menu item in the EditorWindow class that does something like:

self.text.tag_remove("sel", "1.0", "end")
self.text.delete("1.0", "end")

and perhaps some more tag management of which I'm unaware of.

查看更多
登录 后发表回答