在Python IDLE中實現清屏

2021-08-03 03:37:00 字數 2558 閱讀 8936

螢幕東西太多,需要清屏,在windows的視窗清屏命令是cls,在python idle中的快捷鍵是ctrl+l

"""

clear window extension

version: 0.2

author: roger d. serwy

[email protected]

date: 2009-06-14

it provides "clear shell window" under "options"

with ability to undo.

add these lines to config-extensions.def

[clearwindow]

enable=1

enable_editor=0

enable_shell=1

[clearwindow_cfgbindings]

clear-window="""

class

clearwindow:

menudefs = [

('options', [none,

('clear shell window', '<>'),

]),]

def__init__

(self, editwin):

self.editwin = editwin

self.text = self.editwin.text

self.text.bind("<>", self.clear_window2)

self.text.bind("<>", self.undo_event) # add="+" doesn't work

defundo_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")

defclear_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', '

self.text.mark_set('insert', 'end-1c')

self.editwin.set_line_and_column()

defclear_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', '

self.text.mark_set('insert', 'end-1c')

self.editwin.set_line_and_column()

# restore undo delegator

self.editwin.per.insertfilter(undo)

[clearwindow]

enable=1

enable_editor=0

enable_shell=1

[clearwindow_cfgbindings]

clear-window=

開啟python的idle,看看options是不是多了乙個選項clear shell window ctrl+l

這時ctrl+l就可以實現清屏了

Python IDLE中實現清屏

將這個檔案放在python x lib idlelib目錄下 x為你的python版本 然後在這個目錄下找到config extensions.def這個檔案 idle擴充套件的配置檔案 以記事本的方式開啟它 開啟config extensions.def 後在句末加上這樣幾句 clearwindo...

Mac中實現python IDLE清屏

clear window extension version 0.2 author roger d.serwy roger.serwy gmail.com date 2009 06 14 it provides clear shell window under options with abilit...

在 中實現 加密

在 中的專案中,新增引用 system.web 然後 str2 system.web.security.formsauthentication.hashpasswordforstoringinconfigfile str1,md5 就ok了,如果要換成 sha1 加密形式,只要把 md5 換成 md...