【问题标题】:Problems with refreshing terminal刷新终端的问题
【发布时间】:2015-04-28 15:58:44
【问题描述】:

我在刷新终端时遇到问题。我正在使用带有curses模块的python。有随机名称生成器,它在启动程序时在预定义文本旁边显示生成的名称。用户可以修改名称(添加/删除字符)。

问题出在哪里?在屏幕开始时仅显示预定义的文本。输入了生成的名称,但所有字符都是黑色的,用户看不到它。仅在修改名称时刷新屏幕,即用户添加新字母或删除最后一个字母。

我想在生成名称后刷新屏幕。

算法:(GetStringName 函数的一部分)

    str = true_heroname #generated name
    self.screen.move(y, x + len(str))
    self.screen.refresh()                   #it should refresh screen after placing generated name
    self.screen.addstr(y, x, prompt, pattr)
    x += len(prompt)
    while True:
        self.screen.move(y, x + len(str))
        self.screen.refresh()
        ####AND BELOW CODE TO ADD/REMOVE LETTERS###

此函数用于在主菜单中生成名称:

    self.name = Global.IO.GetStringName("What's your name? ", noblank=True, pattr=c_yellow, iattr=c_Yellow)
    #c_yellow and c_Yellow are predefinied colors

我希望描述和剪断的代码清晰。

如何在输入生成名称后自动刷新屏幕?

【问题讨论】:

  • 信息不足(简短而完整的程序会有所帮助)。

标签: python python-2.7 terminal refresh curses


【解决方案1】:

您的帖子并没有让我完全清楚您的问题,但如果我指出一种在屏幕上绘制的一般方式,也许会有所帮助。 我假设您的 self.screen 是实际的诅咒stdscr

while True:
    userinput = self.screen.getch() # User enters character

    # Move to start of terminal
    # This may not be necessary depending on your application
    curses.move(self.screen, 0, 0) 

    # Do your drawing here, depending on what char the user entered
    # ...
    self.screen.addstr("Hello world!")

    curses.clrtobot(self.screen) # Clear remainder of the screen
    self.screen.refresh() # Refresh terminal, to show new drawings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-27
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2021-02-26
    相关资源
    最近更新 更多