『壹』 跪求關於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 如何清除屏幕內容

方法:

  1. python自帶的idle沒有這個功能,你可以pip install idlex

  2. 就是進入一個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上的清屏代碼:

-----

希望可以幫到題主, 歡迎追問.