码迷,mamicode.com
首页 > 编程语言 > 详细

Python-IDLE实现清屏

时间:2019-03-22 00:29:14      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:odi   python36   provides   class   color   The   python3   1.0   author   

 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>

 

Python-IDLE实现清屏

标签:odi   python36   provides   class   color   The   python3   1.0   author   

原文地址:https://www.cnblogs.com/larken/p/9633156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!