python - Python 诅咒如何用 curses.setsyx(y,x) 改变光标位置?
问题描述
我正在学习如何使用诅咒,我正在尝试创建一个简单的程序来开始。我希望这个程序总是在左上角打印 aq,然后它会在 1,1 中打印最近按下的字符。但我不确定如何设置光标的位置,应该使用 curses.setsyx(y,x) 函数来更改它,但它不起作用。这是我的程序:
import curses
import sys,os
def screen_init(stdscr):
stdscr.clear()
stdscr.refresh()
stdscr.scrollok(1)
height, width = stdscr.getmaxyx()
curses.start_color()
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
while True:
stdscr.addstr(0, 0, "q", curses.color_pair(1))
key = stdscr.getch()
stdscr.addstr(1, 1, chr(int(key)), curses.color_pair(1))
if key == ord('q'):
break
elif key == ord('p'):
curses.setsyx(3, 3)
curs_y, curs_x = curses.getsyx()
curses.doupdate()
stdscr.addstr(1, 1, "clicked! " + str(curs_x) + " " +
str(curs_y), curses.color_pair(1))
stdscr.refresh()
curses.endwin()
def main():
curses.wrapper(screen_init)
if (__name__ == "__main__"):
main();
关于它为什么不做任何事情的任何想法?当我使用 getyx() 它得到 3, 3 但光标的真实位置没有改变
解决方案
你可以使用stdscr.getyx()
andstdscr.move(y, x)
代替。
推荐阅读
- python - 散点图 Z 轴上的 DMY H:M 格式
- docker - 如何在 Kubernetes 上使用 Docker 运行 Jenkins?
- python - 分析日志文件时如何获得所有行的输出?
- android - 我的基本 Android 应用程序在闪屏后关闭
- javascript - 使用 ajax 结果作为带有 async/await 的变量
- python - 为什么 sorted() 函数在传递 3 个参数时说它只需要一个参数?
- sql - 甲骨文根据足球结果创建联赛表
- reactjs - 在 findOneDocument 与返回文档上的精益()之后调用精益() - 为什么在返回的文档上调用精益()不起作用?
- pari - 在 mac 上安装和使用 Pari/gp
- html - MatSidenav 中的 Angular Material UI 错误:无法设置未定义的属性“fixedTopGap”