python清除屏幕
『壹』 跪求关于python如何清屏的问题,
windows下是
import os
os.system("cls")
Linux下是
import os
os.system("clear")
如果是IDE下,没有办法
『贰』 Python Shell 怎样清屏
Python Shell中清屏一般有两种方法。
1、使用os模块
importos#加载os模块
os.system("cls")#windows上执行cls命令
os.system("clear")#linux上执行clear命令
上图是linux上的示例,按下回车键后,马上清除所有显示内容。
『叁』 python shell 中怎么实现清屏
Python Shell有两种方式,分别为“Windows命令行窗口”和“IDLE”
“命令行窗口”下可以通过如下两种方法:
1. import subprocess
subprocess.call("clear") # linux/mac
subprocess.call("cls", shell=True) # windows
执行完次命令后,窗口顶部第一行会出现一个0,接下来才会是输入提示符“>>>”
消除这个0的方法是在此命令前添加一个变量,例如 i=subprocess.call("cls", shell=True)
2. import os
os.system("cls") # windows
os.system("clear") # linux
执行完次命令后,窗口顶部第一行也会出现一个0,接下来才会是输入提示符“>>>”
消除这个0的方法同方法1
“IDLE”下以上两种方式都不起作用,可以通过建立如下函数实现:
1、伪清屏
def cls():
print "
"*80 #Shell 3.0+ 改为 print(('
'*80))
此函数将命令行往下移动80行,数字80可以自己任意设定
这是伪清屏,只是输入满屏的空格而已
2、插件法
首先下载clearwindow.py,将这个文件放在Python XLibidlelib目录下(X为python版本),然后在这个目录下找到config-extensions.def这个文件(idle扩展的配置文件),以记事本的方式打开它(为防止出错,可以在打开它之前先一个备份)。打开config-extensions.def 后在句末加上这样几句:
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
然后保存退出即可。
打开python的idle,看看options是不是多了一个选项clear shell window ctrl+L
如果是这样的话,那就证明安装成功了,以后要清屏直接ctrl+L就可以了
附clearwindow.py代码:
classClearWindow:
menudefs=[
('options',[None,
('ClearShellWindow','<<clear-window>>'),
]),]
def__init__(self,editwin):
self.editwin=editwin
self.text=self.editwin.text
self.text.bind("<<clear-window>>",self.clear_window2)
self.text.bind("<<undo>>",self.undo_event)#add="+"doesn'twork
defundo_event(self,event):
text=self.text
text.mark_set("iomark2","iomark")
text.mark_set("insert2","insert")
self.editwin.undo.undo_event(event)
#fixiomarkandinsert
text.mark_set("iomark","iomark2")
text.mark_set("insert","insert2")
text.mark_unset("iomark2")
text.mark_unset("insert2")
defclear_window2(self,event):#Alternativemethod
#
text=self.text
text.undo_block_start()
text.mark_set("iomark2","iomark")
text.mark_set("iomark",1.0)
text.delete(1.0,"iomark2linestart")
text.mark_set("iomark","iomark2")
text.mark_unset("iomark2")
text.undo_block_stop()
ifself.text.compare('insert','<','iomark'):
self.text.mark_set('insert','end-1c')
self.editwin.set_line_and_column()
defclear_window(self,event):
#removeundodelegator
undo=self.editwin.undo
self.editwin.per.removefilter(undo)
#clearthewindow,butpreservecurrentcommand
self.text.delete(1.0,"iomarklinestart")
ifself.text.compare('insert','<','iomark'):
self.text.mark_set('insert','end-1c')
self.editwin.set_line_and_column()
#restoreundodelegator
self.editwin.per.insertfilter(undo)
『肆』 python 如何清除屏幕内容
方法:
python自带的idle没有这个功能,你可以pip install idlex
就是进入一个python程序 然后隔几秒把数据清除掉 然后重新打印数据
『伍』 如何清空python中graphics的屏幕内容
我们也在做这个,找这个方法找了好久,没找到,想了个办法,就是画一个矩形(整个graphics窗口这么大),然后用setFill给矩形涂上白色,就清屏了,为了方便的话,可以自己定义这样一个方法。
『陆』 python idle怎么清屏
打开config-extensions.def 后在句末加上这样几句:
[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
然后保存退出就可以了。
打开python的idle,看看options是不是多了一个选项clear shell window ctrl+L
如果是这样的话,那就证明你安装成功了,以后要清屏直接ctrl+L就可以了
『柒』 python如何在界面上实现清屏,求教
import os
os.system("clear") # on windows usage: os.system("cls")
『捌』 python清屏代码
题主你好,
linux|mac上的清屏代码:
-----
希望可以帮到题主, 欢迎追问.