Python3.7.0 Shell添加清屏快捷键的实现示例
作者:???fu?? 时间:2023-02-25 13:39:23
1、找到python的安装目录在python (版本号)\lib\idlelib目录下
添加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扩展配置文件)
在原文件下添加如下代码:
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-w>
3、重新启动IDLE,点击Options,可看到:
输入一些代码
Ctrl+w
即可完成清屏!!!!到此这篇关于Python3.7.0 Shell添加清屏快捷键的实现示例的文章就介绍到这了,更多相关Python Shell添加清屏内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
来源:https://blog.csdn.net/k13629129790/article/details/105030010
标签:Python,Shell,清屏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
opencv实现简单人脸识别
2021-08-26 07:49:06
![](https://img.aspxhome.com/file/2023/6/75096_0s.jpg)
交互设计实用指南系列(3)—“有效性”之“适时帮助”
2009-12-25 14:29:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/04d4365a20d52fbefe705991235bec36-87s.gif)
Python编程基础之类和对象
2023-08-04 11:52:33
![](https://img.aspxhome.com/file/2023/7/61437_0s.jpg)
使用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
![](https://img.aspxhome.com/file/2023/7/76707_0s.jpg)
ASP在线生成电话图片程序
2007-10-06 23:06:00
![](https://img.aspxhome.com/file/UploadPic/200710/6/200710623165632s.gif)
如何提高Request集合的使用效率?
2010-06-07 20:53:00
实例讲解启动mysql server失败的解决方法
2008-12-26 17:27:00
十分钟搞定pandas(入门教程)
2023-08-09 01:00:15
![](https://img.aspxhome.com/file/2023/0/63950_0s.jpg)
Python入门_浅谈逻辑判断与运算符
2023-11-09 05:45:26
![](https://img.aspxhome.com/file/2023/8/64668_0s.png)
python实现图片,视频人脸识别(dlib版)
2023-03-28 14:35:19
Python 统计数据集标签的类别及数目操作
2023-04-08 12:04:09
![](https://img.aspxhome.com/file/2023/8/77678_0s.png)
sql server常用命令行操作(启动、停止、暂停)
2012-01-05 19:02:48
Django渲染Markdown文章目录的方法示例
2021-03-31 05:12:07
![](https://img.aspxhome.com/file/2023/9/81569_0s.jpg)
python的简单web框架flask快速实现详解
2023-03-10 08:26:36
![](https://img.aspxhome.com/file/2023/2/77712_0s.png)
Python之str操作方法(详解)
2021-07-21 09:14:16
Oracle数据库的安全策略
2010-07-31 13:13:00
以用户为中心的WEB表单
2010-08-03 12:11:00
![](https://img.aspxhome.com/file/UploadPic/20108/3/01-37s.jpg)
一文详解Python灰色预测模型实现示例
2023-05-11 01:45:21
![](https://img.aspxhome.com/file/2023/6/76126_0s.png)