Skip to main content
 首页 » 编程设计

python之创建菜单(覆盖以前的输出)

2025年05月04日21jyk

我想用 Python 创建一个菜单,它将显示如下内容:

-----Help menu----- 
 
Hello and welcome to the help menu! 
 
Press Enter to continue.  

困难的部分是我希望之前的输出(从“hello”到“continue”)消失。因此,当我按下 Enter 时,将显示为:

-----Help menu----- 
 
The first step is to....  
 
Press Enter to continue.  

我曾尝试使用 \r 但不允许我使用 Press Enter 东西。

请您参考如下方法:

您可以使用清晰屏幕做您想做的事。

如果您在 Windows 上,只需在您的 python 代码上执行此操作:

import os 
os.system('cls') 

如果你在 Linux 上(你可能想要的)就这样做:

import os 
os.system('clear') 

有了它,您将能够从屏幕上清除之前的输出并插入新的输出。