【问题标题】:Text added to New window is not visible in Curses添加到新窗口的文本在诅咒中不可见
【发布时间】:2018-05-10 12:45:04
【问题描述】:

我正在尝试使用 this 在该窗口中添加一个带有诅咒的窗口和一个文本:

window.addstr("This is a text in a window")

代码:

class View:
    def __init__(self, ):
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.cbreak()
        self.stdscr.keypad(True)
        # -----------------
        self.add_window_and_str()
        self.add_str()
        # -----------------
        self.stdscr.getkey()
        curses.endwin()

    def add_str(self): #just text in standart screen
        self.stdscr.addstr("test")
        self.stdscr.refresh()

    def add_window_and_str(self):
        scr_limits = self.stdscr.getmaxyx()
        win = curses.newwin(scr_limits[0] - 10, scr_limits[1] - 10, 5, 5)
        win.addstr("Example String")
        win.refresh()
        self.stdscr.refresh()

使用self.add_str 添加的文本可见,但“示例字符串”不可见。 如何操作窗口以使该文本可见?

【问题讨论】:

    标签: python python-3.x curses python-curses


    【解决方案1】:

    在初始化时,标准屏幕有一个挂起的更新(以清除屏幕)。在add_window_and_str 末尾的refresh 调用会覆盖win.addstr 输出。您可以在第一次调用add_window_and_str之前将该调用移至add_window_and_str。之后,对stdscr 的更改将出现在窗口外的部分屏幕中。

    还有一个问题:调用getch 会刷新关联的窗口。通常程序是这样组织的,以便getch 与您希望保持“顶部”的任何窗口相关联,以便它们的更新不会被其他窗口遮挡。如果您从add_window_and_str 返回win 变量,则可以将该窗口与getch 一起使用。

    【讨论】:

    • 我想,我需要使用面板让两个不同的东西一起显示出来。
    • 这让它变得更简单,但如果你牢记刷新在 curses 中的工作方式,你可以让窗口按照你想要的方式运行,对于简单的 2 窗口配置(添加窗口会更难)。
    猜你喜欢
    • 2022-08-14
    • 2013-06-10
    • 2012-03-28
    • 1970-01-01
    • 2018-06-08
    • 2020-03-25
    • 2014-04-22
    • 1970-01-01
    • 2013-10-26
    相关资源
    最近更新 更多