(Python2,Python3 通用)

保存如下代码到 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)

将上述文件保存到 C:\Python27\Lib\idlelib 下。再打开此目录下的 config-extensions.def 文件,在其尾部添加如下代码

################################# >>> Added for clear Window
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>

好了,现在 IDLE 已经可以支持 Ctrl + l 清屏了。

注意:如果遇到 IDLE 快捷键冲突 (我在 Ubuntu 18.04 的 Python3.6.8 IDLE 中遇到过),例如 IDLE 默认已经定义了 Ctrl + l 为其它用途快捷键,则可以在 IDLE 菜单 Options -> Configure IDLE -> Keys 重新设定快捷键,如下图:

以上方法同样适用于 Linux。在 Linux 下,上述两个文件应该位于: /usr/lib/python2.7/idlelib  或  /usr/lib/python3.4/idlelib    /usr/lib64/python2.7/idlelib

完。

Python IDLE 增加清屏功能的更多相关文章

  1. Python IDLE配置清屏快捷键(Ctrl+L)

    1.在Python\Lib\idlelib下,新建一个ClearWindow.py文件(没有时就新建),内容如下: """ Clear Window Extension ...

  2. My first Python program(附增加清屏方法)

    #TempConvert.py TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['F', 'f']: C = (eval(Te ...

  3. Python IDLE如何清屏

    金gordon 原文 IDLE如何清屏 在学习和使用python的过程中,少不了要与Python IDLE打交道.但使用 Python IDLE 都会遇到一个常见而又懊恼的问题——要怎么清屏? 答案是 ...

  4. python中的清屏函数

    一:cmd中python的清屏函数 import os os.system("cls") cmd中演示 1.在cmd中输入命令行: 2.执行后: 3.为什么会遗留一个0? 因为函数 ...

  5. python添加清屏功能

    创建文件ClearWindow添加内容 class ClearWindow: menudefs = [ ('options', [None, ('Clear Shell Window', '<& ...

  6. Python IDLE 代码高亮主题

    Python IDLE 代码高亮主题 使用方法: 打开C盘我的 C:\Documents and Settings\你的用户名.idlerc文件夹 里面会有一个 config-highlight.cf ...

  7. x8086汇编实现dos清屏(clear screen)

    题目要求:x8086汇编实现dos下的清屏功能 80X25彩色字符模式显示缓冲区的结构: 在内存地址结构中,B8000H~BFFFFH共32KB的空间,为80x25彩色字符模式的显示缓冲区.向这个地址 ...

  8. Python:IDLE清屏

    清屏很简单,为IDLE增加一个清屏的扩展ClearWindow即可. 首先下载clearwindow.py(点击可直接下载,不能下载的可以右键保存,格式为py结尾), 将这个文件放到Python安装目 ...

  9. python idle 清屏问题的解决

    在学习和使用python的过程中,少不了要与python idle打交道.但使用python idle都会遇到一个常见而又懊恼的问题——要怎么清屏?   我在stackoverflow看到这样两种答案 ...

随机推荐

  1. CSS使用position:sticky 实现粘性布局

    简介 前面写了一篇文章讲解了position常用的几个属性:<CSS 属性之 position讲解>一般都知道下面几个常用的: { position: static; position: ...

  2. 正则去除html字符串中的注释、标签、属性

    var str = '<!-- 注释1 --><h1 style="color:#00ff00;text-align: center;">ProsperLe ...

  3. 如何用ABP框架快速完成项目(2) - 快的定义!

    为什么要从快的角度来讲这系列课程呢?   因为快是一个很统一很清晰的标准. 所有人对时间都有一个统一清晰的概念.  比如说这系列课程会讲到的一个实例: 集成LinqToExcel, 用我的方法大概耗时 ...

  4. bat 批处理获取时间语法格式

    bat 批处理获取时间语法格式 取年份:echo %date:~0,4%  取月份:echo %date:~5,2%  取日期:echo %date:~8,2%  取星期:echo %date:~10 ...

  5. getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()

    一.getCacheDir.getCacheDir getCacheDir()方法用于获取/data/data//cache目录 getFilesDir()方法用于获取/data/data//file ...

  6. Windows系统java下载与安装

    Windows系统java下载与安装 一.前言 作者:深圳-风尘 联系方式:QQ群[585499566] 博客:https://www.cnblogs.com/1fengchen1/ 能读懂本文档人: ...

  7. 章节七、3-ArrayList和LinkedList对比

    一.创建集合并添加元素(从末尾位置添加) package ZangJie7; import java.util.ArrayList; import java.util.LinkedList; impo ...

  8. (面试题)python面试题集锦-附答案

    1.一行代码实现1-100的和 sum_1_100 = sum(range(1, 101)) 2.如何在一个函数内修改全局变量的值 a = 100 def foo(): global a a = 30 ...

  9. ES搜索引擎集群模式搭建【Kibana可视化】

    一.简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎(与Solr类似),基于RESTful web接口.Elasticsearch是用Ja ...

  10. SQL 中事务的分类

    先讲下事务执行流程: BEGIN和COMMIT PRINT @@TRANCOUNT --@@TRANCOUNT统计事务数量 BEGIN TRAN PRINT @@TRANCOUNT BEGIN TRA ...