如何给python3.6.5IDLE SHELL增加清屏功能
1、在shell里用requests读取一个网页。

2、将网页的内容显示以后,cup的使用率就上去了,shell变的很卡,于是想到是不是显示的内容太多了?能不能有清屏功能。到网上找了一下,还真有,实践了一把,成功了!

3、将网上的代码复制或者保存到ClearWindow.py
"""
Clear Window Extension
Version: 0.2
Author: Roger D. Serwy
roger.serwy@gmail.com
Date: 2009-06-14
It provides "Clear Shell Window" under "Options"
with ability to undo.
Add these lines to config-extensions.def
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
"""
class ClearWindow:
menudefs = [
('options', [None,
('Clear Shell Window', '<<clear-window>>'),
]),]
def __init__(self, editwin):
self.editwin = editwin
self.text = self.editwin.text
self.text.bind("<<clear-window>>", self.clear_window2)
self.text.bind("<<undo>>", self.undo_event) # add="+" doesn't work
def undo_event(self, event):
text = self.text
text.mark_set("iomark2", "iomark")
text.mark_set("insert2", "insert")
self.editwin.undo.undo_event(event)
# fix iomark and insert
text.mark_set("iomark", "iomark2")
text.mark_set("insert", "insert2")
text.mark_unset("iomark2")
text.mark_unset("insert2")
def clear_window2(self, event): # Alternative method
# work around the ModifiedUndoDelegator
text = self.text
text.undo_block_start()
text.mark_set("iomark2", "iomark")
text.mark_set("iomark", 1.0)
text.delete(1.0, "iomark2 linestart")
text.mark_set("iomark", "iomark2")
text.mark_unset("iomark2")
text.undo_block_stop()
if self.text.compare('insert', '<', 'iomark'):
self.text.mark_set('insert', 'end-1c')
self.editwin.set_line_and_column()
def clear_window(self, event):
# remove undo delegator
undo = self.editwin.undo
self.editwin.per.removefilter(undo)
# clear the window, but preserve current command
self.text.delete(1.0, "iomark linestart")
if self.text.compare('insert', '<', 'iomark'):
self.text.mark_set('insert', 'end-1c')
self.editwin.set_line_and_column()
# restore undo delegator
self.editwin.per.insertfilter(undo)

4、具体的步骤是这些。

5、然后把ClearWindow.py复制到C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Lib\idlelib,也就是你的安装目录的相应文件夹下。

6、然后给这个目录下的config-extensions.def建立备份(出错了可以挽回啦),然后用记事本打开原件。

7、在末尾添加如下内容,然后保存退出:
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-;>

8、重新运行shell以后,发现options下多了一个按钮。

9、对了,我查看了下这里才有的。

10、最初的猜想也是对的,清屏以后,程序运行又流畅了。

