关于python清屏

对于不知道自己python安装目录的,可以通过python的idle查看,打开idle,然后输入import sys,然后输入sys.path,就可以找到了,然后去到idlelib文件夹里,创建一个ClearWindows.py文件,将以下代码复制并保存到ClearWindows.py。

class ClearWindow:

    menudefs = [
        ('options', [None,
               ('Clear Shell Window', '<>'),
       ]),]
 
    def __init__(self, editwin):
        self.editwin = editwin
        self.text = self.editwin.text
        self.text.bind("<>", 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)

接下来就是在idlelib文件夹里找到config-extensions.def配置文件,也就是当前目录,然后打开在文件末尾添加

[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=

然后打开idle,你就会发现菜单栏options多了一个清屏选项,快捷键就是用Ctrl+L,至此结束

你可能感兴趣的:(python,pyton的idle清屏,清屏)