手把手教你怎么让Python IDLE清屏 idle清屏设置
1、开始之前,我们必须要知道:
IDLE默认没有清屏功能,所以我们想要使其可以实现清屏,我们就必须要扩展IDLE。
我们需要下载一个叫ClearWindow.py的扩展文件
如图
2、其代码如下:
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_window)
def clear_window2(self, event): # Alternative method
# work around the ModifiedUndoDelegator
text = self.text
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")
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)
小伙伴可以复制以上代码保存成一个ClearWindow.py文件
同样,我们也可以到bugs.python.org/file14116/ClearWindow.py去复制保存。
3、我们打开Python的安装目录,找到Lib目录下的idlelib目录
然后把上面保存的ClearWindow.py拷贝到idlelib目录下。
找到config-extensions.def配置文件并打开它。
如图
4、在文件末尾加入以下配置:
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
来解释下什么意思
enable=1
#1为真 意思就是启用这个扩展
enable_editor=0
#编辑器禁用这个扩展
enable_shell=1
#IDLE Shell启动扩展
clear-window=<Control-Key-l>
#设置快捷键为Ctrl + L
5、此时我们打开Python IDLE Shell
点击Options,可以看到我们的扩展被成功加载。
同样,我们可以按下Ctrl + L进行清屏操作。我们还可以通过clear-window=<Control-Key-l>修改快捷键,例如修改为ctrl + 3,则是clear-window=<Control-Key-3>
怎么样,学会没?点一波关注吧(*^__^*)
1、怎么关注?
在经验的右上角小编头像旁边点击关注,如图。
2、怎么点赞?
请在经验左侧点赞,如图。
3、怎么投票?
在经验的下方点击投票,如图。
4、如果觉得小编写的还不错,可以动动鼠标把它分享给您的朋友。
如何分享,鼠标移动到右下角第一个按钮上,在弹出的选项中进行分享,如图。
不尽感激。