【问题标题】:Using Python 3 curses in only a small part of the terminal仅在终端的一小部分使用 Python 3 curses
【发布时间】:2019-02-21 09:53:13
【问题描述】:

有没有一种方法可以启动诅咒只占据屏幕的一部分,同时允许常规打印在屏幕上方输出?

因此,在这个提供的示例中,所有正常的打印语句都将转到常规终端,并在程序完成后持续存在。

import curses
from curses import wrapper
from time import sleep
import random


def main(stdscr):
    stdscr.nodelay(True)
    stdscr.clear()
    participants = 5
    positions = dict()
    for i in range(participants):
    positions[i] = 0
    completed = 0
    game_winner = -1
    while True:
    _c = stdscr.getch()
    round_winner = random.randint(0, participants-1)

    winner_position = positions[round_winner]
    if winner_position < 10:
        positions[round_winner] = winner_position + 1

    stdscr.clear()
    for i in range(participants):
        position = positions[i]
        stdscr.addstr(i, 0, str(i+1) + ": ")
        stdscr.addstr(i, position+3, 'x')
        if position == 10:
            if game_winner < 0:
                game_winner = i + 1
            print(str(i + 1) + " completed the race!")
            positions[round_winner] = position + 1
            completed += 1
    sleep(1)
    if completed >= len(positions):
        break

    print("The winner is " + str(game_winner) + "!")


wrapper(main)

【问题讨论】:

    标签: curses python-curses


    【解决方案1】:

    问题是

    有没有一种方法可以启动诅咒只占据屏幕的一部分,同时允许常规打印在屏幕上方输出?

    实际上不是:你可以告诉 curses 假装它正在使用一个较小的屏幕,但在这种情况下它会使用屏幕顶部(通过设置 LINES 环境变量)和/或左侧部分(通过设置COLUMNS),但这不会阻止它使用擦除来清除屏幕的“未使用”部分。

    【讨论】:

      猜你喜欢
      • 2011-07-06
      • 2018-04-25
      • 2012-03-18
      • 2012-05-25
      • 2011-09-28
      • 1970-01-01
      • 2011-05-02
      • 2011-06-14
      • 1970-01-01
      相关资源
      最近更新 更多