gpt4 book ai didi

windows - 如何在 Python 命令行应用程序上创建静态标题/边框

转载 作者:可可西里 更新时间:2023-11-01 13:37:01 25 4
gpt4 key购买 nike

我正在使用 Python cmd 模块创建 CLI 应用程序。一切都很好!但是,我正在尝试针对特定类型的存在定制应用程序:文本颜色、标题、使用字母数字字符作为边框等。

是否有创建各种屏幕溢出的标准方法:我设置边框和颜色标题的屏幕顶部保持不变?从屏幕中间或附近一直到屏幕底部,在提示符处输入的任何文本或命令在到达标题/边框时都将不再可见。基本上,我所追求的是让用户始终看到标题/边框,除非他们退出 CLI 应用程序。如果他们输入帮助,当然,他们会在标题/边框下方看到命令。但是,当他们输入命令时,理想情况下,命令菜单会消失在屏幕标题/边框后面。

任何有关我实现此目标的最佳方式的指导都将受到赞赏。

最佳答案

检查 curses

您应该能够使用颜色和静态边框装饰 CLI/终端。

我扩展了取自 HERE 的示例:

import curses
from multiprocessing import Process

p = None
def display(stdscr):
stdscr.clear()
stdscr.timeout(500)

maxy, maxx = stdscr.getmaxyx()
curses.newwin(2,maxx,3,1)

# invisible cursor
curses.curs_set(0)

if (curses.has_colors()):
# Start colors in curses
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_RED, -1)
stdscr.refresh()

curses.init_pair(1, 0, -1)
curses.init_pair(2, 1, -1)
curses.init_pair(3, 2, -1)
curses.init_pair(4, 3, -1)

bottomBox = curses.newwin(8,maxx-2,maxy-8,1)
bottomBox.box()
bottomBox.addstr("BottomBox")
bottomBox.refresh()
bottomwindow = curses.newwin(6,maxx-4,maxy-7,2)
bottomwindow.addstr("This is my bottom view", curses.A_UNDERLINE)
bottomwindow.refresh()

stdscr.addstr("{:20s}".format("Hello world !"), curses.color_pair(4))
stdscr.refresh()

while True:
event = stdscr.getch()
if event == ord("q"):
break

def hang():
while True:
temp = 1 + 1

if __name__ == '__main__':
p = Process(target = hang)
curses.wrapper(display)

关于windows - 如何在 Python 命令行应用程序上创建静态标题/边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48915550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com