相信有良多在Windows上利用Python的小伙伴城市想過如許一個問題——Python怎么樣才能在IDLE清屏?IDLE是沒有如許的功能的 。
其實 , 我們可以擴展IDLE , 使得我們在開辟和測試的時辰加倍便當 。
今天小編就教大師怎么擴展IDLE , 使其撐持清屏功能 。

需要這些哦
Python for Windows
方式/
1起頭之前 , 我們必需要知道:
IDLE默認沒有清屏功能 , 所以我們想要使其可以實現清屏 , 我們就必需要擴展IDLE 。
我們需要下載一個叫ClearWindow.py的擴展文件
如圖

2其代碼如下:
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_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', '-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', '-1c')
self.editwin.set_line_and_column()
# restore undo delegator
self.editwin.per.insertfilter(undo)
小伙伴可以復制以上代碼保留當作一個ClearWindow.py文件
同樣 , 我們也可以到bugs.python.org/file14116/ClearWindow.py去復制保留 。

3我們打開Python的安裝目次 , 找到Lib目次下的idlelib目次
然后把上面保留的ClearWindow.py拷貝到idlelib目次下 。
找到config-extensions.def設置裝備擺設文件并打開它 。
猜你喜歡
- 怎么為文本框設置陰影效果
- word標尺怎么調出來
- 感謝老師的付出怎么說 有哪些感謝老師付出的句子
- favourite怎么發音
- 怎么申請全國計算機等級考試證書直郵
- 一月至十二月的英語單詞怎么寫?
- 四六級收音機怎么用
- 定語從句思維導圖怎么做
- 英語四級考試時間怎么分配?
- Mac上怎么查找和刪除“mshelper”惡意軟件
