Python IDLE清屏,,在学习和使用Pyth
Python IDLE清屏,,在学习和使用Pyth
在学习和使用Python的过程中,少不了要与Python IDLE打交道。但使用 Python IDLE 都会遇到一个常见而又懊恼的问题——要怎么清屏?答案是为IDLE增加一个清屏的扩展ClearWindow就可以了(在Issue 6143: IDLE中可以看到这个扩展的说明)。下面我说说安装使用的方法。1、下载ClearWindow.py(最下面有代码,保存为ClearWindow.py)。2、拷贝ClearWindow.py文件,放在Python安装目录Python XXX\Lib\idlelib下面(XXX为你的python版本)。3、记事本打开Python XXX\Lib\idlelib目录下的config-extensions.def(IDLE扩展的配置文件), 为防止出错,你可以在打开它之前先copy一个备份 。4、修改config-extensions.def ,在末尾添加如下内容,然后保存退出:[ClearWindow]enable=1enable_editor=0enable_shell=1[ClearWindow_cfgBindings]clear-window=<Control-Key-;>5、打开Python的IDLE,options选项中就可以看到增加了Clear Shell Window ctrl+;。6、在IDLE输入代码,然后按Ctrl+;(是指Ctrl和;),发现刚输入代码可以被清除了。1 """ 2 3 Clear Window Extension 4 Version: 0.2 5 6 Author: Roger D. Serwy 7 roger.serwy@gmail.com 8 9 Date: 2009-06-1410 11 It provides "Clear Shell Window" under "Options"12 with ability to undo.13 14 Add these lines to config-extensions.def15 16 [ClearWindow]17 enable=118 enable_editor=019 enable_shell=120 [ClearWindow_cfgBindings]21 clear-window=<Control-Key-l>22 23 24 """25 26 class ClearWindow:27 28 menudefs = [29 (‘options‘, [None,30 (‘Clear Shell Window‘, ‘<<clear-window>>‘),31 ]),]32 33 def __init__(self, editwin):34 self.editwin = editwin35 self.text = self.editwin.text36 self.text.bind("<<clear-window>>", self.clear_window2)37 38 self.text.bind("<<undo>>", self.undo_event) # add="+" doesn‘t work39 40 def undo_event(self, event):41 text = self.text42 43 text.mark_set("iomark2", "iomark")44 text.mark_set("insert2", "insert")45 self.editwin.undo.undo_event(event)46 47 # fix iomark and insert48 text.mark_set("iomark", "iomark2")49 text.mark_set("insert", "insert2")50 text.mark_unset("iomark2")51 text.mark_unset("insert2")52 53 54 def clear_window2(self, event): # Alternative method55 # work around the ModifiedUndoDelegator56 text = self.text57 text.undo_block_start()58 text.mark_set("iomark2", "iomark")59 text.mark_set("iomark", 1.0)60 text.delete(1.0, "iomark2 linestart")61 text.mark_set("iomark", "iomark2")62 text.mark_unset("iomark2")63 text.undo_block_stop()64 if self.text.compare(‘insert‘, ‘<‘, ‘iomark‘):65 self.text.mark_set(‘insert‘, ‘end-1c‘)66 self.editwin.set_line_and_column()67 68 def clear_window(self, event):69 # remove undo delegator70 undo = self.editwin.undo71 self.editwin.per.removefilter(undo)72 73 # clear the window, but preserve current command74 self.text.delete(1.0, "iomark linestart")75 if self.text.compare(‘insert‘, ‘<‘, ‘iomark‘):76 self.text.mark_set(‘insert‘, ‘end-1c‘)77 self.editwin.set_line_and_column()78 79 # restore undo delegator80 self.editwin.per.insertfilter(undo)ClearWindow.py作者:知乎用户链接:https://www.zhihu.com/question/20917976/answer/32876441来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
Python IDLE清屏
相关内容
- Python Numpy中数据的常用的保存与读取方法,,在经常性读
- 使用python 写一个 股票涨跌提醒功能,,1: 安装pytho
- centos7下载python3环境,,1.centos7自
- 【Python】Java程序员学习Python(七)— 文本类详解(字
- python修改镜像源,,python修改镜像
- python一键刷屏,,#当按键q的时候,自
- python3.6.2利用pyinstaller发布EXE,, 我的环境是Ubu
- python爬取微博热搜,,功能利用python
- Python enumerate() 函数,,描述enumerat
- python编程webpy框架模板之def with学习,
评论关闭