Save the following code to clearwindow.py
"" "Clear Window extensionversion:0.2author:roger D. Serwy [Email protected]date:2009-06-14it provides" Clea R Shell Window "under" options with ability to undo. Add these lines to config-extensions.def[clearwindow]enable=1enable_editor=0enable_shell=1[clearwindow_cfgbindings ]clear-window=<control-key-l> "" "Class clearwindow:menudefs = [(' Options ', [None], (' Clear S Hell 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 = s Elf.text text.mark_set ("Iomark2", "Iomark") Text.mark_set ("Insert2", "Insert") self.editwin.u Ndo.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 Clea R_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_blo Ck_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.E Ditwin.undo Self.editwin.per.removefilter (undo) # Clear the window, but preserve-command self . Text.delete (1.0, "Iomark linestart") if Self.text.compare (' Insert ', ' < ', ' Iomark '): self.text.mark_s ET (' Insert ', ' end-1c ') Self.editwin.set_line_and_column () # Restore undo Delegator Self.editwin.per.insertfilter (undo)
Save the above file to C:\Python27\Lib\idlelib. Then open the Config-extensions.def file in this directory and add the following code to its tail
################################# >>> Added for Clear Window[clearwindow]enable=1enable_editor=0enable_ Shell=1[clearwindow_cfgbindings]clear-window=<control-key-l>
OK, now IDLE can support ctrl+l clear the screen.
Finish.
Python IDLE adds clear screen function