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之print详解
Sep 28 Python
详解Python的单元测试
Apr 28 Python
python递归删除指定目录及其所有内容的方法
Jan 13 Python
利用python 更新ssh 远程代码 操作远程服务器的实现代码
Feb 08 Python
Python3实现购物车功能
Apr 18 Python
Python多进程原理与用法分析
Aug 21 Python
python利用requests库模拟post请求时json的使用教程
Dec 07 Python
Python合并2个字典成1个新字典的方法(9种)
Dec 19 Python
使用pyhon绘图比较两个手机屏幕大小(实例代码)
Jan 03 Python
python 使用递归回溯完美解决八皇后的问题
Feb 26 Python
Python json模块与jsonpath模块区别详解
Mar 05 Python
Python unittest生成测试报告过程解析
Sep 08 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 session 错误
2009/05/21 PHP
PHP5 操作MySQL数据库基础代码
2009/09/29 PHP
PHP框架Swoole定时器Timer特性分析
2014/08/19 PHP
PHP中__FILE__、dirname与basename用法实例分析
2014/12/01 PHP
php 参数过滤、数据过滤详解
2015/10/26 PHP
一波PHP中cURL库的常见用法代码示例
2016/05/06 PHP
Yii2组件之多图上传插件FileInput的详细使用教程
2016/06/20 PHP
浅谈PHP正则中的捕获组与非捕获组
2016/07/18 PHP
Javascript表达式中连续的 &amp;&amp; 和 || 之赋值区别
2010/10/17 Javascript
JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
2011/07/04 Javascript
cookie的复制与使用记住用户名实现代码
2013/11/04 Javascript
javascript判断并获取注册表中可信任站点的方法
2015/06/01 Javascript
Ionic快速安装教程
2016/06/03 Javascript
最丑的时钟效果!js canvas时钟制作方法
2016/08/15 Javascript
微信小程序中post方法与get方法的封装
2017/09/26 Javascript
你应该知道的几类npm依赖包管理详解
2017/10/06 Javascript
解决node-sass偶尔安装失败的方法小结
2018/12/05 Javascript
NProgress显示顶部进度条效果及使用详解
2019/09/21 Javascript
javascript History对象原理解析
2020/02/17 Javascript
详解JavaScript作用域 闭包
2020/07/29 Javascript
Python中的rfind()方法使用详解
2015/05/19 Python
python运行其他程序的实现方法
2017/07/14 Python
Windows环境下python环境安装使用图文教程
2018/03/13 Python
Python实现模拟登录网易邮箱的方法示例
2018/07/05 Python
Python实现的微信支付方式总结【三种方式】
2019/04/13 Python
在python plt图表中文字大小调节的方法
2019/07/08 Python
python用quad、dblquad实现一维二维积分的实例详解
2019/11/20 Python
python 根据列表批量下载网易云音乐的免费音乐
2020/12/03 Python
python绘图模块之利用turtle画图
2021/02/12 Python
HTML5移动端手机网站开发流程
2016/04/25 HTML / CSS
德国价格合理的品牌商品购物网站:averdo
2019/03/21 全球购物
商场消防演习方案
2014/02/12 职场文书
安全宣传标语
2014/06/10 职场文书
县委常委班子专题民主生活会查摆问题及整改措施
2014/09/27 职场文书
2015年店长工作总结范文
2015/04/08 职场文书
法律讲堂观后感
2015/06/11 职场文书