How to clear the screen with Python's own idle

Source: Internet
Author: User
Tags clear screen

User link: https://www.zhihu.com/question/20917976/answer/32876441 Source: The copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source. In the process of learning and using Python, there is no need to deal with Python idle. But using Python IDLE will encounter a common and annoying question--How do I clear the screen? The answer is to add a clear screen extension ClearWindow for IDLE (you can see the extension in issue 6143:idle). Let me tell you how to use the installation. 1, download clearwindow.py (most of the code below, Save as clearwindow.py). 2, copy the clearwindow.py file, put in Python installation directory Python xxx\lib\idlelib (XXX for your Python version). 3, Notepad open the Python xxx\lib\idlelib directory under the config-extensions.def (Idle extension configuration file), in order to prevent errors, you can open it before you copy a backup. 4, modify the Config-extensions.def, add the following at the end, and then save the exit: [Clearwindow]enable=1enable_editor=0enable_shell=1[clearwindow_ cfgbindings]clear-window=<control-key-;>5, open Python's idle,options option, you can see the addition of the Clear Shell window Ctrl +;.   6. In the idle input code, and then press CTRL +; (refers to Ctrl and;), discovering that the input code can be cleared. clearwindow.py
 """Clear Window Extensionversion:0.2author:roger D. Serwy [Email Protected]date:2009-06-14it provides "clear Sh ell 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>"""classClearwindow: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    defundo_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 insertText.mark_set ("Iomark","IOMARK2") Text.mark_set ("Insert","Insert2") Text.mark_unset ("IOMARK2") Text.mark_unset ("Insert2")            defClear_window2 (self, event):#Alternative Method#Work around the ModifiedundodelegatorText =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 ()ifSelf.text.compare ('Insert','<','Iomark'): Self.text.mark_set ('Insert','end-1c') Self.editwin.set_line_and_column ()defClear_window (Self, event):#Remove undo DelegatorUndo =Self.editwin.undo self.editwin.per.removefilter (undo)#clear the window, but preserve current commandSelf.text.delete (1.0,"Iomark Linestart")        ifSelf.text.compare ('Insert','<','Iomark'): Self.text.mark_set ('Insert','end-1c') Self.editwin.set_line_and_column ()#Restore undo DelegatorSelf.editwin.per.insertfilter (undo)

How to clear the screen with Python's own idle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.