【问题标题】:Display properly output messages using npyscreen使用 npyscreen 正确显示输出消息
【发布时间】:2022-06-23 21:37:23
【问题描述】:

我有一个脚本,它使用 npyscreen 收集初始信息,然后在它进行时显示多条消息。但是,这些消息以杂乱无章的方式显示(见下文)。有没有办法以正确的方式(不带标签)填充这些消息?

Something
         Something
                  Something

这是代码

import npyscreen, time

class Test(npyscreen.NPSApp):
    def main(self):

        F  = npyscreen.Form(name = "Test")

        color = F.add(npyscreen.TitleText, name = "Color:")
        
        F.edit()        

        if(color.value == "Something"):
            self.call_function_to_display_messages(color.value)


    def call_function_to_display_messages(self, color):

        print(color)
        print(color)
        print(color)
        time.sleep(10)

if __name__ == "__main__":
    App = Test()
    App.run()

【问题讨论】:

    标签: python npyscreen


    【解决方案1】:

    解决方法是在打印语句的开头加上回车。

    print("\r"+color)
    

    【讨论】:

      猜你喜欢
      • 2016-06-27
      • 1970-01-01
      • 2016-04-04
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 2015-07-03
      • 1970-01-01
      相关资源
      最近更新 更多