Python?IDLE設(shè)置清屏快捷鍵的方法詳解
實(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)能正常使用。

到此這篇關(guān)于Python IDLE設(shè)置清屏快捷鍵的方法詳解的文章就介紹到這了,更多相關(guān)Python IDLE清屏內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Django連接數(shù)據(jù)庫(kù)并實(shí)現(xiàn)讀寫分離過程解析
這篇文章主要介紹了Django連接數(shù)據(jù)庫(kù)并實(shí)現(xiàn)讀寫分離過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11
Python?seaborn數(shù)據(jù)可視化繪圖(直方圖,密度圖,散點(diǎn)圖)
這篇文章主要介紹了Python?seaborn數(shù)據(jù)可視化繪圖(直方圖,密度圖,散點(diǎn)圖),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07
Python進(jìn)階之遞歸函數(shù)的用法及其示例
本篇文章主要介紹了Python進(jìn)階之遞歸函數(shù)的用法及其示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01
使用Pytest.main()運(yùn)行時(shí)參數(shù)不生效問題解決
本文主要介紹了使用Pytest.main()運(yùn)行時(shí)參數(shù)不生效問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
Python 統(tǒng)計(jì)數(shù)據(jù)集標(biāo)簽的類別及數(shù)目操作
這篇文章主要介紹了Python 統(tǒng)計(jì)數(shù)據(jù)集標(biāo)簽的類別及數(shù)目操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05
Python抖音快手代碼舞(字符舞)的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于Python抖音快手代碼舞的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
Python實(shí)現(xiàn)簡(jiǎn)單的多任務(wù)mysql轉(zhuǎn)xml的方法
這篇文章主要介紹了Python實(shí)現(xiàn)簡(jiǎn)單的多任務(wù)mysql轉(zhuǎn)xml的方法,結(jié)合實(shí)例形式分析了Python查詢mysql結(jié)果集轉(zhuǎn)xml格式數(shù)據(jù)輸出的相關(guān)操作技巧,需要的朋友可以參考下2017-02-02

