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中删除文件的程序代码
Mar 13 Python
python3访问sina首页中文的处理方法
Feb 24 Python
Python3.0与2.X版本的区别实例分析
Aug 25 Python
python 写入csv乱码问题解决方法
Oct 23 Python
Python_LDA实现方法详解
Oct 25 Python
python pyheatmap包绘制热力图
Nov 09 Python
浅谈pycharm的xmx和xms设置方法
Dec 03 Python
python实现词法分析器
Jan 31 Python
Python如何调用JS文件中的函数
Aug 16 Python
python的json包位置及用法总结
Jun 21 Python
Java Unsafe类实现原理及测试代码
Sep 15 Python
matplotlib源码解析标题实现(窗口标题,标题,子图标题不同之间的差异)
Feb 22 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 破解防盗链图片函数
2008/12/09 PHP
php二维数组排序与默认自然排序的方法介绍
2013/04/27 PHP
ThinkPHP视图查询详解
2014/06/30 PHP
php远程下载类分享
2016/04/13 PHP
jQuery 表单验证扩展代码(二)
2010/10/20 Javascript
JS刷新当前页面的几种方法总结
2013/12/24 Javascript
jQuery实现二级下拉菜单效果
2016/01/05 Javascript
javascript类型系统 Array对象学习笔记
2016/01/09 Javascript
第二章之Bootstrap 页面排版样式
2016/04/25 Javascript
深入理解JavaScript中的并行处理
2016/09/22 Javascript
JS树形菜单组件Bootstrap TreeView使用方法详解
2016/12/21 Javascript
Angular4学习笔记之实现绑定和分包
2017/08/01 Javascript
Vue.js实现价格计算器功能
2020/03/30 Javascript
Vue拖拽组件开发实例详解
2018/05/11 Javascript
vue获取时间戳转换为日期格式代码实例
2019/04/17 Javascript
Element实现表格分页数据选择+全选所有完善批量操作
2019/06/07 Javascript
[00:52]DOTA2齐天大圣预告片
2016/08/13 DOTA
python3图片转换二进制存入mysql
2013/12/06 Python
Python正则表达式使用经典实例
2016/06/21 Python
Python中多个数组行合并及列合并的方法总结
2018/04/12 Python
解决python写入mysql中datetime类型遇到的问题
2018/06/21 Python
python实现两个dict合并与计算操作示例
2019/07/01 Python
Python实现搜索算法的实例代码
2020/01/02 Python
Tensorflow 模型转换 .pb convert to .lite实例
2020/02/12 Python
Python日志syslog使用原理详解
2020/02/18 Python
pycharm激活码免费分享适用最新pycharm2020.2.3永久激活
2020/11/25 Python
Python实现树莓派摄像头持续录像并传送到主机的步骤
2020/11/30 Python
webView加载html图片遇到的问题解决
2019/10/08 HTML / CSS
家庭户外服装:Hawkshead
2017/11/02 全球购物
电钳专业个人求职信
2014/01/04 职场文书
户籍证明格式
2014/09/15 职场文书
2014年大堂经理工作总结
2014/11/21 职场文书
2014年党总支工作总结
2014/12/18 职场文书
红白喜事主持词
2015/07/06 职场文书
幼儿园托班开学寄语(2016秋季)
2015/12/03 职场文书
解析mybatis-plus中的resultMap简单使用
2021/11/23 Java/Android