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

作者:???fu?? 时间:2023-02-25 13:39:23 

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添加清屏内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

来源:https://blog.csdn.net/k13629129790/article/details/105030010

标签:Python,Shell,清屏
0
投稿

猜你喜欢

  • opencv实现简单人脸识别

    2021-08-26 07:49:06
  • 交互设计实用指南系列(3)—“有效性”之“适时帮助”

    2009-12-25 14:29:00
  • Python编程基础之类和对象

    2023-08-04 11:52:33
  • 使用python解析xml成对应的html示例分享

    2022-05-05 21:02:27
  • Python获取当前函数名称方法实例分享

    2023-12-22 01:16:57
  • Python调用Windows API函数编写录音机和音乐播放器功能

    2021-06-13 19:03:55
  • ASP在线生成电话图片程序

    2007-10-06 23:06:00
  • 如何提高Request集合的使用效率?

    2010-06-07 20:53:00
  • 实例讲解启动mysql server失败的解决方法

    2008-12-26 17:27:00
  • 十分钟搞定pandas(入门教程)

    2023-08-09 01:00:15
  • Python入门_浅谈逻辑判断与运算符

    2023-11-09 05:45:26
  • python实现图片,视频人脸识别(dlib版)

    2023-03-28 14:35:19
  • Python 统计数据集标签的类别及数目操作

    2023-04-08 12:04:09
  • sql server常用命令行操作(启动、停止、暂停)

    2012-01-05 19:02:48
  • Django渲染Markdown文章目录的方法示例

    2021-03-31 05:12:07
  • python的简单web框架flask快速实现详解

    2023-03-10 08:26:36
  • Python之str操作方法(详解)

    2021-07-21 09:14:16
  • Oracle数据库的安全策略

    2010-07-31 13:13:00
  • 以用户为中心的WEB表单

    2010-08-03 12:11:00
  • 一文详解Python灰色预测模型实现示例

    2023-05-11 01:45:21
  • asp之家 网络编程 m.aspxhome.com