Python3.7.0 Shell添加清屏快捷键的实现示例


Posted in Python onMarch 23, 2020

1、找到python的安装目录在python (版本号)\lib\idlelib目录下

Python3.7.0 Shell添加清屏快捷键的实现示例

添加Clearwindow.py文件

源代码如下:

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)

2、继续在当前目录下(python (版本号)\lib\idlelib)打开编辑config-extensions.def(IDLE扩展配置文件)

Python3.7.0 Shell添加清屏快捷键的实现示例

在原文件下添加如下代码:

[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-w>

3、重新启动IDLE,点击Options,可看到:

Python3.7.0 Shell添加清屏快捷键的实现示例

输入一些代码

Python3.7.0 Shell添加清屏快捷键的实现示例

Ctrl+w

Python3.7.0 Shell添加清屏快捷键的实现示例

即可完成清屏!!!!到此这篇关于Python3.7.0 Shell添加清屏快捷键的实现示例的文章就介绍到这了,更多相关Python Shell添加清屏内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
Python实现队列的方法
May 26 Python
python处理大数字的方法
May 27 Python
python文件操作相关知识点总结整理
Feb 22 Python
Python实现将一个大文件按段落分隔为多个小文件的简单操作方法
Apr 17 Python
Python字典及字典基本操作方法详解
Jan 30 Python
ubuntu安装mysql pycharm sublime
Feb 20 Python
Python使用爬虫爬取静态网页图片的方法详解
Jun 05 Python
python如何爬取个性签名
Jun 19 Python
解决django model修改添加字段报错的问题
Nov 18 Python
python 字段拆分详解
Dec 17 Python
python如何输出反斜杠
Jun 18 Python
django下创建多个app并设置urls方法
Aug 02 Python
Python面向对象程序设计之继承、多态原理与用法详解
Mar 23 #Python
python实现图像拼接功能
Mar 23 #Python
Python猴子补丁Monkey Patch用法实例解析
Mar 23 #Python
Python面向对象程序设计之静态方法、类方法、属性方法原理与用法分析
Mar 23 #Python
Python3 pickle对象串行化代码实例解析
Mar 23 #Python
Python面向对象程序设计之类和对象、实例变量、类变量用法分析
Mar 23 #Python
Python3 shelve对象持久存储原理详解
Mar 23 #Python
You might like
PHP 删除一个目录及目录下的所有文件的函数代码
2010/05/26 PHP
php截取后台登陆密码的代码
2012/05/05 PHP
工厂模式在Zend Framework中应用介绍
2012/07/10 PHP
typecho插件编写教程(二):写一个新插件
2015/05/28 PHP
腾讯CMEM的PHP扩展编译安装方法
2015/09/25 PHP
PHP中JSON的应用技巧
2015/10/10 PHP
PHP简单创建压缩图的方法
2016/08/24 PHP
PHP里面把16进制的图片数据显示在html的img标签上(实现方法)
2017/05/02 PHP
jQuery 1.4 15个你应该知道的新特性(译)
2010/01/24 Javascript
Jquery实现图片放大镜效果的思路及代码(自写)
2013/10/18 Javascript
Javascript基础 函数“重载” 详细介绍
2013/10/25 Javascript
用JS生成UUID的方法实例
2016/03/30 Javascript
JavaScript计算器网页版实现代码分享
2016/07/15 Javascript
JavaScript原生编写《飞机大战坦克》游戏完整实例
2017/01/04 Javascript
Angular.js中$resource高大上的数据交互详解
2017/07/30 Javascript
微信小程序实现导航栏选项卡效果
2020/06/19 Javascript
Vue 实现双向绑定的四种方法
2018/03/16 Javascript
angularjs下ng-repeat点击元素改变样式的实现方法
2018/09/12 Javascript
详解Vue中组件的缓存
2019/04/20 Javascript
JS代码检查工具ESLint介绍与使用方法
2020/02/04 Javascript
详解JavaScript之ES5的继承
2020/07/08 Javascript
解决Vue-Router升级导致的Uncaught (in promise)问题
2020/08/07 Javascript
python正则表达式爬取猫眼电影top100
2018/02/24 Python
tf.truncated_normal与tf.random_normal的详细用法
2018/03/05 Python
Python上下文管理器类和上下文管理器装饰器contextmanager用法实例分析
2019/11/07 Python
使用Keras建立模型并训练等一系列操作方式
2020/07/02 Python
pycharm 添加解释器的方法步骤
2020/08/31 Python
泰国综合购物网站:Lazada泰国
2018/04/09 全球购物
美国眼镜在线零售商:Dualens
2019/12/07 全球购物
全球性的众包图形设计市场:DesignCrowd
2021/02/02 全球购物
中专药剂专业应届毕的自我评价
2013/12/27 职场文书
应聘编辑自荐信范文
2014/03/12 职场文书
党员弘扬焦裕禄精神思想汇报
2014/09/10 职场文书
市委常委会班子党的群众路线教育实践活动整改方案
2014/10/25 职场文书
2019新学期家长会工作计划
2019/08/21 职场文书
详细介绍Java中的CyclicBarrier
2022/04/13 Java/Android