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 11 Python
简单的Python的curses库使用教程
Apr 11 Python
Python中遇到的小问题及解决方法汇总
Jan 11 Python
python发送邮件实例分享
Jul 28 Python
Python button选取本地图片并显示的实例
Jun 13 Python
Python QQBot库的QQ聊天机器人
Jun 19 Python
pygame实现五子棋游戏
Oct 29 Python
Python数据可视化图实现过程详解
Jun 12 Python
TensorFlow-gpu和opencv安装详细教程
Jun 30 Python
导致python中import错误的原因是什么
Jul 01 Python
利用django创建一个简易的博客网站的示例
Sep 29 Python
python 实现全球IP归属地查询工具
Dec 18 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提示Warning:phpinfo() has been disabled函数禁用的解决方法
2014/12/17 PHP
php+mysqli实现将数据库中一张表信息打印到表格里的方法
2015/01/28 PHP
PHP实现的贪婪算法实例
2017/10/17 PHP
浅谈php使用curl模拟多线程发送请求
2019/03/08 PHP
PHP判断访客是否手机端(移动端浏览器)访问的方法总结【4种方法】
2019/03/27 PHP
PHP实现简单用户登录界面
2019/10/23 PHP
ThinkPHP5.1+Ajax实现的无刷新分页功能示例
2020/02/10 PHP
javascript 控制弹出窗口
2007/04/10 Javascript
Javascript结合css实现网页换肤功能
2009/11/02 Javascript
jQuery实现的Email中的收件人效果(按del键删除)
2011/03/20 Javascript
js实现简单鼠标跟随效果的方法
2015/04/10 Javascript
png在IE6 下无法透明的解决方法汇总
2015/05/21 Javascript
js实现选中复选框文字变色的方法
2015/08/14 Javascript
AngularJS入门教程之双向绑定详解
2016/08/18 Javascript
利用JS实现页面删除并重新排序功能
2016/12/09 Javascript
jQuery ajax实现省市县三级联动
2021/03/07 Javascript
JS简单生成随机数(随机密码)的方法
2017/05/11 Javascript
jQuery事件blur()方法的使用实例讲解
2019/03/30 jQuery
vue使用codemirror的两种用法
2019/08/27 Javascript
Python解决鸡兔同笼问题的方法
2014/12/20 Python
Python在Console下显示文本进度条的方法
2016/02/14 Python
浅析Python中的多条件排序实现
2016/06/07 Python
Python实现压缩和解压缩ZIP文件的方法分析
2017/09/28 Python
Python整数对象实现原理详解
2019/07/01 Python
tensorflow 实现自定义梯度反向传播代码
2020/02/10 Python
Python 操作 PostgreSQL 数据库示例【连接、增删改查等】
2020/04/21 Python
Django DRF路由与扩展功能的实现
2020/06/03 Python
Python numpy矩阵处理运算工具用法汇总
2020/07/13 Python
详解pytorch中squeeze()和unsqueeze()函数介绍
2020/09/03 Python
达拉斯牛仔官方商店:Dallas Cowboys Pro Shop
2018/02/10 全球购物
计算机专业大学生的自我评价
2013/11/14 职场文书
小学数学课题方案
2014/06/15 职场文书
妇产科护理心得体会
2016/01/22 职场文书
85句关于理想的名言警句大全
2019/08/22 职场文书
上帝为你开了一扇窗之Tkinter常用函数详解
2021/06/02 Python
OpenCV-Python使用cv2实现傅里叶变换
2021/06/09 Python