日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Python?IDLE設(shè)置清屏快捷鍵的方法詳解_python

作者:夢(mèng)里逆天 ? 更新時(shí)間: 2022-11-02 編程語(yǔ)言

實(shí)現(xiàn)步驟:

新建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)

將ClearWindow.py復(fù)制到python安裝目錄下的Lib\idlelib目錄(比如我的是:D:\Softwares\Python\Python310\Lib\idlelib)

修改idlelib目錄下的config-extensions.def。修改之前最好先復(fù)制一份作為備份。

在文件末尾添加如下內(nèi)容:

[ClearWindow]
enable = True
enable_editor = False
enable_shell = True
[ClearWindow_cfgBindings]
clear-window = <Control-Key-l>

保存文件并關(guān)閉。

啟動(dòng)IDLE

點(diǎn)擊"Options",會(huì)發(fā)現(xiàn)多了一個(gè)選項(xiàng)“Clear Shell Window”。

隨便輸入一些指令

按快捷鍵Ctrl+L(或者鼠標(biāo)點(diǎn)擊“Options”,選擇“Clear Shell Window”。

再輸入指令,發(fā)現(xiàn)能正常使用。

原文鏈接:https://blog.csdn.net/username666/article/details/126756301

欄目分類(lèi)
最近更新