Python-IDLE实现清屏
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Python-IDLE实现清屏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                             1 1、將下面文件復制到命名為ClearWindow.py的文件下,移動到 …Python\Python36-32\Lib\idlelib下。
 2 ###################################################################################
 3 """
 4 
 5 Clear Window Extension
 6 Version: 0.2
 7 
 8 Author: Roger D. Serwy
 9         roger.serwy@gmail.com
10 
11 Date: 2009-06-14
12 
13 It provides "Clear Shell Window" under "Options"
14 with ability to undo.
15 
16 Add these lines to config-extensions.def
17 
18 [ClearWindow]
19 enable=1
20 enable_editor=0
21 enable_shell=1
22 [ClearWindow_cfgBindings]
23 clear-window=<Control-Key-l>
24 
25 
26 """
27 
28 class ClearWindow:
29 
30     menudefs = [
31         ('options', [None,
32                ('Clear Shell Window', '<<clear-window>>'),
33        ]),]
34          
35     def __init__(self, editwin):
36         self.editwin = editwin
37         self.text = self.editwin.text
38         self.text.bind("<<clear-window>>", self.clear_window2)
39 
40         self.text.bind("<<undo>>", self.undo_event)  # add="+" doesn't work
41 
42     def undo_event(self, event):
43         text = self.text
44         
45         text.mark_set("iomark2", "iomark")
46         text.mark_set("insert2", "insert")
47         self.editwin.undo.undo_event(event)
48 
49         # fix iomark and insert
50         text.mark_set("iomark", "iomark2")
51         text.mark_set("insert", "insert2")
52         text.mark_unset("iomark2")
53         text.mark_unset("insert2")
54         
55 
56     def clear_window2(self, event): # Alternative method
57         # work around the ModifiedUndoDelegator
58         text = self.text
59         text.undo_block_start()
60         text.mark_set("iomark2", "iomark")
61         text.mark_set("iomark", 1.0)
62         text.delete(1.0, "iomark2 linestart")
63         text.mark_set("iomark", "iomark2")
64         text.mark_unset("iomark2")
65         text.undo_block_stop()
66         if self.text.compare('insert', '<', 'iomark'):
67             self.text.mark_set('insert', 'end-1c')
68         self.editwin.set_line_and_column()
69 
70     def clear_window(self, event):
71         # remove undo delegator
72         undo = self.editwin.undo
73         self.editwin.per.removefilter(undo)
74 
75         # clear the window, but preserve current command
76         self.text.delete(1.0, "iomark linestart")
77         if self.text.compare('insert', '<', 'iomark'):
78             self.text.mark_set('insert', 'end-1c')
79         self.editwin.set_line_and_column()
80  
81         # restore undo delegator
82         self.editwin.per.insertfilter(undo)
83 ###################################################################################
84 2、接下來就是要在 …Python\Python36-32\Lib\idlelib文件夾下,用記事本打開文件config-extensions.def,在文件最后添加一下代碼: 
85 [ClearWindow] 
86 enable=1 
87 enable_editor=0 
88 enable_shell=1 
89 [ClearWindow_cfgBindings] 
90 clear-window=<Control-Key-l>  
                        
                        
                        ?
轉載于:https://www.cnblogs.com/larken/p/9633156.html
總結
以上是生活随笔為你收集整理的Python-IDLE实现清屏的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 搭建微服务器:express+https
 - 下一篇: 01背包 || BZOJ 1606: [