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

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

(0)

相关推荐

  • Python中调用PowerShell、远程执行bat文件实例

    python调用本地powershell方法 1.现在准备一个简陋的powershell脚本,功能是测试一个IP列表哪些可以ping通: 复制代码 代码如下: function test_ping($iplist) {     foreach ($myip in $iplist)     {         $strQuery = "select * from win32_pingstatus where address = '$myip'"         # 利用 Get-WmiO

  • Python 运行 shell 获取输出结果的实例

    首先使用内置模块os. >>> import os >>> code = os.system("pwd && sleep 2") # /User/zhipeng >>> print code # 0 问题是 os.system 只能获取到结束状态 使用内置模块 subprocess >>> import subprocess >>> subprocess.Popen("p

  • Python封装shell命令实例分析

    本文实例讲述了Python封装shell命令的方法.分享给大家供大家参考.具体实现方法如下: # -*- coding: utf-8 -*- import os import subprocess import signal import pwd import sys class MockLogger(object): '''模拟日志类.方便单元测试.''' def __init__(self): self.info = self.error = self.critical = self.deb

  • Nodejs中调用系统命令、Shell脚本和Python脚本的方法和实例

    每种语言都有自己的优势,互相结合起来各取所长程序执行起来效率更高或者说哪种实现方式较简单就用哪个,nodejs是利用子进程来调用系统命令或者文件,文档见http://nodejs.org/api/child_process.html,NodeJS子进程提供了与系统交互的重要接口,其主要API有: 标准输入.标准输出及标准错误输出的接口. NodeJS 子进程提供了与系统交互的重要接口,其主要 API 有: 标准输入.标准输出及标准错误输出的接口 child.stdin 获取标准输入 child.

  • python调用shell的方法

    1.1  os.system(command) 在一个子shell中运行command命令,并返回command命令执行完毕后的退出状态.这实际上是使用C标准库函数system()实现的.这个函数在执行command命令时需要重新打开一个终端,并且无法保存command命令的执行结果. 1.2  os.popen(command,mode) 打开一个与command进程之间的管道.这个函数的返回值是一个文件对象,可以读或者写(由mode决定,mode默认是'r').如果mode为'r',可以使用

  • python和shell变量互相传递的几种方法

    python -> shell: 1.环境变量 复制代码 代码如下: import os  var=123或var='123'os.environ['var']=str(var)  #environ的键值必须是字符串   os.system('echo $var') 复制代码 代码如下: import os  var=123或var='123'os.environ['var']=str(var)  #environ的键值必须是字符串  os.system('echo $var') 2.字符串连接

  • Python与shell的3种交互方式介绍

    概述 考虑这样一个问题,有hello.py脚本,输出"hello, world!":有TestInput.py脚本,等待用户输入,然后打印用户输入的数据.那么,怎么样把hello.py输出内容发送给TestInput.py,最后TestInput.py打印接收到的"hello, world!".下面我来逐步讲解一下shell的交互方式. hello.py代码如下: 复制代码 代码如下: #!/usr/bin/python print "hello, wor

  • 在python 中实现运行多条shell命令

    使用py时可能需要连续运行多条shell 命令 1. # coding: UTF-8 import sys reload(sys) sys.setdefaultencoding('utf8') import subprocess import os import commands #os.system('cmd1 && cmd2') cmd1 = "cd ../" cmd2 = "ls" cmd = cmd1 + " &&

  • python执行使用shell命令方法分享

    1. os.system(shell_command) 直接在终端输出执行结果,返回执行状态0,1 此函数会启动子进程,在子进程中执行command,并返回command命令执行完毕后的退出状态,如果command有执行内容,会在标准输出显示.这实际上是使用C标准库函数system()实现的. 缺点:这个函数在执行command命令时需要重新打开一个终端,并且无法保存command命令的执行结果. os.system('cat /etc/passwdqc.conf') 2. os.popen()

  • python中执行shell的两种方法总结

    一.使用python内置commands模块执行shell commands对Python的os.popen()进行了封装,使用SHELL命令字符串作为其参数,返回命令的结果数据以及命令执行的状态: 该命令目前已经废弃,被subprocess所替代: # coding=utf-8 ''' Created on 2013年11月22日 @author: crazyant.net ''' import commands import pprint def cmd_exe(cmd_String): p

  • python中执行shell命令的几个方法小结

    最近有个需求就是页面上执行shell命令,第一想到的就是os.system, 复制代码 代码如下: os.system('cat /proc/cpuinfo') 但是发现页面上打印的命令执行结果 0或者1,当然不满足需求了. 尝试第二种方案 os.popen() 复制代码 代码如下: output = os.popen('cat /proc/cpuinfo') print output.read() 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的

随机推荐