網站首頁 編程語言 正文
實現步驟:
新建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復制到python安裝目錄下的Lib\idlelib目錄(比如我的是:D:\Softwares\Python\Python310\Lib\idlelib)
修改idlelib目錄下的config-extensions.def。修改之前最好先復制一份作為備份。
在文件末尾添加如下內容:
[ClearWindow]
enable = True
enable_editor = False
enable_shell = True
[ClearWindow_cfgBindings]
clear-window = <Control-Key-l>
保存文件并關閉。
啟動IDLE
點擊"Options",會發現多了一個選項“Clear Shell Window”。
隨便輸入一些指令
按快捷鍵Ctrl+L(或者鼠標點擊“Options”,選擇“Clear Shell Window”。
再輸入指令,發現能正常使用。
原文鏈接:https://blog.csdn.net/username666/article/details/126756301
相關推薦
- 2022-05-11 Springcloud集成Seata分布式事務
- 2022-04-10 MalformedByteSequenceException: 1字節的 UTF-8 序列的字節 1
- 2022-04-12 常見的狀態碼出現原因200、301、302、403、404、500、503
- 2022-06-26 Android開發快速實現底部導航欄示例_Android
- 2022-01-08 使用grid布局解決flex布局最后一行不足的問題
- 2022-02-14 taro將頁面滾動到指定位置
- 2022-10-19 報錯No?module?named?numpy問題的解決辦法_python
- 2023-07-09 el-table操作列的按鈕超過三個時,動態計算,將多余的按鈕放入更多el-dropdown-men
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支