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如何清屏的問題,

windows下是
import os
os.system("cls")
Linux下是
import os
os.system("clear")

如果是IDE下,沒有辦法

㈣ ipynb 下python如何清屏

importos
os.system("cls")#windows
os.system("clear")#linux

㈤ 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清屏代碼

題主你好,

linux|mac上的清屏代碼:

-----

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

㈦ python是否有clrscr之類的可在程序里清屏的函數

import os,然後os.system("……"),那個字元串會當做命令行命令執行。os.system("cls")相當於在命令行里執行"cls",即清屏。
我真見過靠cls不斷清屏寫命令行游戲的

㈧ Python Shell 怎樣清屏

其實就抄是執行操作系統命令:
Windows 下清屏命令 cls
Linux 下清屏命令 clear:其實是翻頁 reset:清屏
操作:
import os
os.system('cls')
os.system('clear')
os.system('reset')

㈨ python如何在界面上實現清屏,求教

import os
os.system("clear") # on windows usage: os.system("cls")

㈩ 【整理】Python的IDLE中如何實現清屏,即IDLE的清屏求解

唯一一個變通的方法是,需要多操作幾步:
1.File-New Window,以打開一個新的窗口Untitled
2.關閉掉原先的Python Shell
3.在新Untitled窗口中,點擊 Run-Python Shell,就可以打開一個,全新的Python shell了,變相的實現了清屏的目的
4.再關閉之前的Untitled的窗口
此法很明顯,很蛋疼。。。
或者說,未必比你關閉Python Shell,重新打開,來的更快。
但是還是算一個方法的。。。。