[英]python curses dynamic value + user input
I'm a bit new to python and curses, so had a few questions. 我对python和curses有点陌生,所以有几个问题。 I'm making a terminal application that uses curses to generate the ui.
我正在制作一个使用curses生成ui的终端应用程序。 I am trying to make something similar to the linux program top except it fetches data from an xml file.
我正在尝试使它类似于linux程序顶部,但它会从xml文件中获取数据。 I have this code that i am modifying from a previous stackoverflow question.
我有从先前的stackoverflow问题修改的这段代码。 To simplify things the dynamic value i'm updating here is just the time.
为简化起见,我在这里更新的动态值只是时间。 My two questions are as follows:
我的两个问题如下:
x = screen.getch(7,2)
to check if the user wants to quit. x = screen.getch(7,2)
检查用户是否要退出。 Similar to top, if the user can type "q" to quit. time.sleep()
command but I wasnt sure if this was the right way to go about it? time.sleep()
命令,但是我不确定这是否是正确的方法? Ideally I'd like to update this with new xml data every 60 seconds or so. I did see this Python/curses user input while updating screen in stackoverflow and i think question is similar but i was a bit overwhelmed by the code. 我确实在更新 stackoverflow的屏幕时看到了这个Python / curses用户输入 ,我认为问题是相似的,但是我对代码有点不知所措。 i dont really understand classes yet and couldnt follow the logic.
我还不太了解课程,也无法遵循逻辑。 i was looking for something simple.
我在寻找简单的东西。 I believe the guy ended up using
line = sys.stdin.read(1)
to get his code running. 我相信这个家伙最终使用
line = sys.stdin.read(1)
来运行他的代码。 I didnt have any luck when using this instead of getch. 当我用这个代替getch时,我没有任何运气。 I got some error about x not being able to use strip().
我收到一些关于x无法使用strip()的错误。
from os import system
import curses
import time
x = 0
while x != ord('q'):
screen = curses.initscr()
curses.curs_set(False)
screen.clear()
screen.border(0)
screen.addstr(1, 2, "BLAH BLAH ",
curses.A_REVERSE)
ltime = time.asctime(time.localtime(time.time()))
screen.addstr(3, 2,'BLAH1: ' + ltime)
screen.addstr(4, 2, "BLAH2")
screen.refresh()
x = screen.getch(7,2)
curses.endwin()
基于一些评论,我在screen=curses.initscr()
之后立即添加了screen.nodelay(True)
screen=curses.initscr()
并能够使其正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.