導航:首頁 > 編程語言 > 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怎樣清屏相關的資料

熱點內容
程序員面試評價 瀏覽:128
手錶加密門禁卡 瀏覽:238
psf已加密 瀏覽:553
返利app怎麼用教程 瀏覽:888
一個程序員寫的詩火了 瀏覽:613
red攝影機壓縮比 瀏覽:410
app賬號怎麼弄 瀏覽:823
hc0551單片機 瀏覽:755
噴淋管道支架演算法 瀏覽:592
壓縮機壞了電腦無法啟動 瀏覽:241
不小心加密了怎麼去掉 瀏覽:955
linux命令行連接db2 瀏覽:898
洪恩app怎麼設置護眼模式 瀏覽:971
小猿口算app怎麼選課時 瀏覽:421
手機號脫敏加密解密 瀏覽:169
台電加密u盤多少錢 瀏覽:547
控制面板文件夾怎麼隱藏 瀏覽:846
opticspdf 瀏覽:593
抖店app怎麼快速退保證金 瀏覽:972
阿里雲伺服器的密碼在哪改 瀏覽:908