導航:首頁 > 編程語言 > python怎樣清屏

python怎樣清屏

發布時間:2024-07-14 00:42:27

python Shell 怎樣清屏

Python Shell中清屏一般有兩種方法。

1、使用os模塊

importos#載入os模塊
os.system("cls")#windows上執行cls命令
os.system("clear")#linux上執行clear命令

上圖是linux上的示例,按下回車鍵後,馬上清除所有顯示內容。

Ⅱ 請問python3有清屏函數(方法)不

用python 執行clean 就可以。

import os
os.system('clear')

Ⅲ 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)

Ⅳ python3.4中如何清屏

在IDLE下清屏:

#網上有些先定義函數,再?print("n" * 100)輸出一百個換行的方法有點扯淡,跟連按回車沒什麼太大區別,游標根本回不到首行。

#還是下面這種方法實用一些。操作好後,只要用ctrl+L就可以清屏了。

#在IDLE下清屏的方法還是比較容易的,請耐心觀看,下面我以圖文結合的形式介紹一下:

1.首先下載ClearWindow.py

2.再將ClearWindow.py文件放在Python XLibidlelib目錄下(X為你的python版本)

python的默認安裝路徑:C:)

3.然後在這個目錄下找到config-extensions.def這個文件

以記事本的方式打開它(為防止出錯,你可以在打開它之前先一個備份)。

打開config-extensions.def 後在句末加上這樣幾句:

[ClearWindow]

enable=1

enable_editor=0

enable_shell=1

[ClearWindow_cfgBindings]

clear-window=<Control-Key-l>

然後保存退出就可以了。

4.重新打開python的IDLE,看看options是不是多了一個選項clear shell window ctrl+L

如果是這樣的話,那就證明你安裝成功了,以後要清屏直接按ctrl+L就可以了。

Ⅳ 在python交互命令行中如何清屏

1、在Windows命令行窗口,顯示內容很多了,需要清屏,輸入cls後,回車。

閱讀全文

與python怎樣清屏相關的資料

熱點內容
魔獸世界單機輸入gm命令 瀏覽:372
51單片機最大負跳距是多少 瀏覽:418
android聊天控制項 瀏覽:128
導致壓縮機壞的原因 瀏覽:295
如何多次選取文件夾 瀏覽:280
android編譯生成odex 瀏覽:233
我的世界聯機俠伺服器如何用指令 瀏覽:94
地鐵逃生戰斗伺服器為什麼進不了 瀏覽:572
加密門卡怎麼模擬小米9 瀏覽:744
核演算法 瀏覽:631
炸彈命令 瀏覽:550
連通路徑演算法 瀏覽:349
phpemptynull 瀏覽:366
安卓手機伺服器地址在哪裡 瀏覽:428
基於單片機的多路控制器課程設計 瀏覽:65
pythonimportsys作用 瀏覽:276
騰訊雲拼團雲伺服器 瀏覽:364
海南離島將加貼溯源碼銷售嗎 瀏覽:244
linux分區讀取 瀏覽:794
單片機液晶顯示屏出現雪花 瀏覽:890