Python-IDLE实现清屏

Posted larken

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python-IDLE实现清屏相关的知识,希望对你有一定的参考价值。

 1 1、将下面文件复制到命名为ClearWindow.py的文件下,移动到 …PythonPython36-32Libidlelib下。
 2 ###################################################################################
 3 """
 4 
 5 Clear Window Extension
 6 Version: 0.2
 7 
 8 Author: Roger D. Serwy
 9         [email protected]
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、接下来就是要在 …PythonPython36-32Libidlelib文件夹下,用记事本打开文件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实现清屏的主要内容,如果未能解决你的问题,请参考以下文章

java实现画图和清屏功能.

C语言部分清屏如何实现

C语言清屏指令

添加ClearWindow.py文件实现IDLE的清屏功能

添加ClearWindow.py文件实现IDLE的清屏功能

Python 集成开发环境(IDE)