我在Python3.4中的ncurses遇到了这个问题,我试图在我的应用程序和代码的布局中设置一些窗口,如下所示:
import curses
import time
class Presentator():
def __init__(self, device_db, address_db):
self.curses_windows = {}
def update_all_windows(self):
for wins in self.curses_windows.values():
wins.noutrefresh()
curses.doupdate()
def update_all_windows(self):
for wins in self.curses_windows.values():
wins.noutrefresh()
curses.doupdate()
def create_windows(self):
max_height = curses.LINES - 5
max_width = curses.COLS - 5
self.curses_windows["border"] = curses.newwin(max_height, max_width, 0, 0)
self.curses_windows["border"].border()
self.curses_windows["title"] = curses.newwin(3, max_width, 0, 0)
self.curses_windows["title"].border()
title_msg = "IP MONITORING"
self.curses_windows["title"].addstr(1, max_width // 2 - len(title_msg), title_msg)
def print_results(self, stdscr):
self.create_windows()
while True:
self.update_all_windows()
time.sleep(5)
def start_ui(self):
curses.wrapper(self.print_results)
if __name__ == "__main__":
p = Presentator()
p.start_ui()
我5次运行两次程序,显示两个有边框的窗口,里面有标题消息IP监控。这是正确的,然而,其余3种情况下只显示了self.curses_windows["border"]
窗口的边框,而没有其他任何情况。我是不是做错了让人耳目一新的事情?为什么结果不可预测?
谢谢你帮忙。
发布于 2016-11-18 02:05:14
当您使用非数字数组索引时,它实际上是一个关联数组(在python中也称为字典)和迭代。
for wins in self.curses_windows.values():
没有预定义的顺序。因此,有时一个窗口最后会被刷新,有时又是另一个窗口。如果你最后写上边框,它就会清除掉“内容”。
https://stackoverflow.com/questions/40659780
复制相似问题