python清屏插件
今天在使用PythonGUI时,被清屏所困扰,查阅网上资源发现一个比较简单的方式。
在python34/Lib/idellib中加入ClearWindow.py。可以到http://bugs.python.org/file14303/ClearWindow.py下载,或者复制以下代码另存为 ClearWindows.py
# IDLEX EXTENSION
## """
## Copyright(C) 2011-2012 The Board of Trustees of the University of Illinois.
## All rights reserved.
##
## Developed by: Roger D. Serwy
## University of Illinois
##
## Permission is hereby granted, free of charge, to any person obtaining
## a copy of this software and associated documentation files (the
## "Software"), to deal with the Software without restriction, including
## without limitation the rights to use, copy, modify, merge, publish,
## distribute, sublicense, and/or sell copies of the Software, and to
## permit persons to whom the Software is furnished to do so, subject to
## the following conditions:
##
## + Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimers.
## + Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimers in the
## documentation and/or other materials provided with the distribution.
## + Neither the names of Roger D. Serwy, the University of Illinois, nor
## the names of its contributors may be used to endorse or promote
## products derived from this Software without specific prior written
## permission.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
## IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
## ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
## CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
## THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
##
##
##
##
## Clear Window Extension
##
## About:
##
## It provides "Clear Shell Window" under "Options"
## with ability to undo.
##
## Part of Issue 6143
##
## """config_extension_def = """
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
"""jn = lambda x,y: '%i.%i' % (x,y) # join integers to text coordinates
sp = lambda x: tuple(map(int, x.split('.'))) # convert tkinter Text coordinate to a line and column tupleimport sys
import re
from idlelib.UndoDelegator import DeleteCommandansi_re = re.compile(r'\x01?\x1b\[(.*?)m\x02?')
def strip_ansi(s):return ansi_re.sub("", s)class ClearWindow:menudefs = [('options', [('Clear Shell Window', '<<clear-window>>'),]),]def __init__(self, editwin):self.editwin = editwinself.text = self.editwin.textself.text.bind("<<clear-window>>", self.clear_window)def clear_window_event(self, ev=None):self.clear_window(ev)return "break"def clear_window(self, event):per = self.editwin.pertext = per.bottomiomark_orig = text.index('iomark')line_io, col_io = sp(iomark_orig)# if cursor is at the prompt, preserve the prompt (multiline)prompt = strip_ansi(sys.ps1)backlines = prompt.count('\n')prompt_start = jn(line_io-backlines, 0)maybe_prompt = text.get(prompt_start, prompt_start + '+%ic' % len(prompt))at_prompt = maybe_prompt == promptif at_prompt:endpos = text.index(prompt_start)else:endpos = text.index('iomark linestart')dump = text.dump('1.0', endpos, all=True)# Add a command to the undo delegatorundo = self.editwin.undoif undo:dc = ClearWindowDeleteCommand('1.0', endpos, dump)undo.addcmd(dc)text.edit_reset() # clear out Tkinter's undo historyclass ClearWindowDeleteCommand(DeleteCommand):def __init__(self, index1, index2, dump):DeleteCommand.__init__(self, index1, index2)self.dump = dumpdef do(self, text):text.delete(self.index1, self.index2)text.see('insert')def redo(self, text):text.delete(self.index1, self.index2)text.see('insert')def undo(self, text):# inspired by "Serializing a text widget" at http://wiki.tcl.tk/9167dump = self.dumptag = {} # remember the index where a tag was activatedfor key, value, index in dump:if key == 'text':text.insert(index, value, '')elif key == 'tagon':tag[value] = indexelif key == 'tagoff':text.tag_add(value, tag[value], index)del tag[value]# extend existing tags to the end positionfor value in tag:text.tag_add(value, tag[value], self.index2)text.see('insert')
然后修改config-extensions.def,在末尾添加
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
这样一来就可以通过快捷键Ctrl+L
来进行清屏了。
网上有一款集成了很多插件的GUI叫 IdleX,将其解压之后放在 Python34/Lib/idlex-1.13,通过python idlex.py可以直接运行,有兴趣的同学可以试试。官网 http://idlex.sourceforge.net
或者大家有更好的方法可以留言一起交流学习。
python清屏插件相关推荐
- python IDLE设置了清屏插件,不起作用怎么办
python IDLE设置了清屏插件,不起作用怎么办 上次随手发了一篇文章,关于如何设置python idle清屏的插件功能.在自己的win10电脑上实现了,但是在另外一台win7电脑上似乎不好使了. ...
- python 清屏_python如何清屏
Python清除屏幕,可以在命令行中导入os模块,然后使用cls来清屏:要想在idle中清理屏幕,需要先下载ClearWindow.py文件,再将此文件放在idlelib文件夹下,在idle窗口中点击 ...
- Python清屏小结
1. cmd–>python import os i = os.system('cls') 2.通用的清屏 def cls(): print("\n"*100) 3.为idl ...
- python 清屏_Python学前准备如果你知道要去哪,那么全世界都给你让路
一.Python 已来 AI 不远 在当今,人工智能已经渗透到了智能手机.网络搜索,广告分发,人脸识别,语音识别,自动驾驶,智能医疗,无人银行等日常生活领域.人工智能的生活化是不可避免的,它将会不可思 ...
- Python 清屏问题的解决
在学习和使用python的过程中,少不了要与python idle打交道.但使用python idle都会遇到一个常见而又懊恼的问题--要怎么清屏? 我在stackoverflow看到这样两种答案: ...
- 关于python清屏
对于不知道自己python安装目录的,可以通过python的idle查看,打开idle,然后输入import sys,然后输入sys.path,就可以找到了,然后去到idlelib文件夹里,创建一个C ...
- python清屏失败_python idle 清屏问题的解决
在学习和使用python的过程中,少不了要与python idle打交道.但使用python idle都会遇到一个常见而又懊恼的问题--要怎么清屏? 我在stackoverflow看到这样两种答案: ...
- Python 清屏方法
1.首先启动Python 有两个方法: 一:cmd import os os.system("cls") #windows os.system("clear") ...
- python自带IDLE清屏设置——ClearWIndow.py
还好吗?诸位,不知道有没有突然想起我? 很多时候不是拿来数据就调参数,训练模型,而是准备工作,对我这个菜鸟来说是这样的,搬砖时候很少,大多数时候都是在找手套,没有手套搬砖一会就干不动了,手都磨破了. ...
最新文章
- 修改mysql用utf8mb4_更改MySQL数据库的编码为utf8mb4
- euv光刻机有什么用_台积电又买了13台EUV光刻机?
- java版hive的UDF(临时函数与永久函数)
- 时间复杂度和空间复杂度探究
- 双系统ubuntu无法进入_win10下安装ubuntu双系统
- ASP.NET MVC 添加Model并连接到本地数据库
- python爬虫微信公众号文章_Python爬虫案例:爬取微信公众号文章
- 微信背后的产品观-学习笔记
- 唤客猫SCRM功能详解(二)
- Kafka配置broker映射错误报错Discovered coordinator xxx rack: null
- Mac10.14版本安装虚拟机Parallels Desktop 14和windows7 64位旗舰版镜像
- 光纤收发器tx和rx是什么意思?二者有什么区别?
- 【python 新浪微博爬虫】python 爬取新浪微博热门话题
- 令人心酸的100个微瞬间 不信你不会被触动 别落泪哦
- Stream流、方法引用知识梳理
- 直播出新规 这些行为会被限制参加活动
- Latex引用参考文献的5种方式
- 用了postman,接口测试不用愁了
- ipmitool sdr type Temperature sdr 从传感器获取某一类数据
- Centos安装MegaCli
热门文章
- axios 封装 (转)
- C#之密封(sealed)的用法
- 三菱PLC以太网模块FX3U-ENET-L的使用方法
- 顶级(top-level window)窗口,被拥有窗口(owned window),子窗口(child window) 与WS_POPUP,WS_CHILD深入浅出
- mysql查询死锁语句_MYSQL查询数据库死锁和事务的语句
- Android 开机流程
- boss直聘一句话介绍优势_boss直聘开场白聊啥?这样做才吸引人!
- Cisco 胖AP简单配置
- 看不到git远程分支
- 2021年全国各地区居民人均可支配收入排行榜:上海、北京人均可支配收入超过7万元,8个省份高于全国平均水平(附年榜TOP31详单)