您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

终端/控制台中的Python控制输出位置

终端/控制台中的Python控制输出位置

对于Windows终端,请尝试控制台模块。对于unix,curses模块可以。

这就是您在Windows上执行此操作的方式。

c = Console.getconsole()
c.text(0, -1, 'And this is the string at the bottom of the console')

通过指定-1第二个参数,字符串位于最底行。

对于Linux,在最后一行打印的工作代码

import time
import curses

def pbar(window):
    height, width = window.getmaxyx()
    for i in range(10):
        window.addstr(height -1, 0, "[" + ("=" * i) + ">" + (" " * (10 - i )) + "]")
        window.refresh()
        time.sleep(0.5)

curses.wrapper(pbar)
python 2022/1/1 18:47:30 有466人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶