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 相关文章推荐
用C++封装MySQL的API的教程
May 06 Python
Python 查看文件的读写权限方法
Jan 23 Python
情人节快乐! python绘制漂亮玫瑰
Aug 18 Python
Python3网络爬虫中的requests高级用法详解
Jun 18 Python
python3.7 使用pymssql往sqlserver插入数据的方法
Jul 08 Python
Python解析命令行读取参数之argparse模块
Jul 26 Python
基于Python安装pyecharts所遇的问题及解决方法
Aug 12 Python
python 实现生成均匀分布的点
Dec 05 Python
查看jupyter notebook每个单元格运行时间实例
Apr 22 Python
解决在keras中使用model.save()函数保存模型失败的问题
May 21 Python
python之语音识别speech模块
Sep 09 Python
Python+Tkinter打造签名设计工具
Apr 01 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
使用VisualStudio开发php的图文设置方法
2010/08/21 PHP
PHP中用正则表达式清除字符串的空白
2011/01/17 PHP
php环境下利用session防止页面重复刷新的具体实现
2014/01/09 PHP
PHP实现的比较完善的购物车类
2014/12/02 PHP
php学习笔记之mb_strstr的基本使用
2018/02/03 PHP
JS中剪贴板兼容性、判断复制成功或失败
2021/03/09 Javascript
$.ajax json数据传递方法
2008/11/19 Javascript
jQuery布局插件UI Layout简介及使用方法
2013/04/03 Javascript
JS在TextArea光标位置插入文字并实现移动光标到文字末尾
2013/06/21 Javascript
jquery ui resize 中border-box的bug修正
2015/04/26 Javascript
JS判断日期格式是否合法的简单实例
2016/07/11 Javascript
JS中BOM相关知识点总结(必看篇)
2016/11/22 Javascript
用jquery的attr方法实现图片切换效果
2017/02/05 Javascript
JavaScript实现星星等级评价功能
2017/03/22 Javascript
three.js实现炫酷的全景3D重力感应
2018/12/30 Javascript
Webpack设置环境变量的一些误区详解
2019/12/19 Javascript
vue实现输入框自动跳转功能
2020/05/20 Javascript
vue 页面回退mounted函数不执行的解决方案
2020/07/26 Javascript
开源Web应用框架Django图文教程
2017/03/09 Python
python分割列表(list)的方法示例
2017/05/07 Python
Python 稀疏矩阵-sparse 存储和转换
2017/05/27 Python
python利用rsa库做公钥解密的方法教程
2017/12/10 Python
python操作列表的函数使用代码详解
2017/12/28 Python
Python求解任意闭区间的所有素数
2018/06/10 Python
python+selenium打印当前页面的titl和url方法
2018/06/22 Python
python 制作自定义包并安装到系统目录的方法
2018/10/27 Python
解决python3 pika之连接断开的问题
2018/12/18 Python
python日期与时间戳的各种转换示例
2020/02/12 Python
Python实现自动打开电脑应用的示例代码
2020/04/17 Python
在Keras中利用np.random.shuffle()打乱数据集实例
2020/06/15 Python
Python __slots__的使用方法
2020/11/15 Python
Geekbuying波兰:购买中国电子产品
2019/10/20 全球购物
如何用Python来进行查询和替换一个文本字符串
2014/01/02 面试题
工商治理实习生的自我评价
2014/01/15 职场文书
《放小鸟》教学反思
2014/04/20 职场文书
电影地道战观后感
2015/06/04 职场文书