1.从https://bugs.python.org/file14116/ClearWindow.py 复制代码将其保存为ClearWindow.py文件
""" Clear Window Extension Version: 0.1 Author: Roger D. Serwy roger.serwy@gmail.com Date: 2009-05-22 It provides "Clear Shell Window" under "Options" Add these lines to config-extensions.def [ClearWindow] enable=1 enable_editor=0 enable_shell=1 [ClearWindow_cfgBindings] clear-window=""" class ClearWindow: menudefs = [ ('options', [None, ('Clear Shell Window', '< >'), ]),] def __init__(self, editwin): self.editwin = editwin self.text = self.editwin.text self.text.bind("< >", self.clear_window) def clear_window2(self, event): # Alternative method # work around the ModifiedUndoDelegator text = self.text 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") 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)
2、打开Python的IDEL配置目录,比如:C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\idlelib
将上面保存的ClearWindow.py拷贝到当前目录下。
3、找到config-extensions.def配置文件并打开它,
在文件最后加入如下配置
[ClearWindow] enable=1 enable_editor=0 enable_shell=1 [ClearWindow_cfgBindings]clear-window=<Control-Key-l>
参数说明:
enable=1 #1为真 意思就是启用这个扩展
enable_editor=0 #编辑器禁用这个扩展
enable_shell=1 #IDLE Shell启动扩展
clear-window=<Control-Key-l> #设置快捷键为Ctrl + L
4.重新启动IDLE,在Options就可以看到Clear Shell Window 菜单