Text added to New window is not visible in Curses

回眸只為那壹抹淺笑 提交于 2020-01-15 18:16:09

问题


I am trying to add a window and a text in this window with curses using this and this:

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

Code:

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()

The text added with self.add_str is visible but the "Example String" is not. How can i manipulate windows to make that text visible?


回答1:


On initialization, the standard screen has a pending update (to clear the screen). The refresh call at the end of add_window_and_str does that, overwriting the win.addstr output. You could move that call before the first call to add_window_and_str. After that, the changes to stdscr would be in parts of the screen outside your window.

There's another problem: calling getch refreshes the associated window. Usually programs are organized so that getch is associated with whatever window you would like to keep "on top", so that their updates will not be obscured by other windows. If you return the win variable from add_window_and_str, you can use that window with getch.



来源:https://stackoverflow.com/questions/50273301/text-added-to-new-window-is-not-visible-in-curses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!