Curses.ADDSTR不会输出到控制台

发布于 2025-02-09 11:52:16 字数 554 浏览 2 评论 0原文

我最近通过py -m pip安装Windows-curses在高架命令提示符中运行的Windows-curses模块在我的计算机上安装了模块。

我编写了以下代码以测试它是否正常工作。如果正确运行,则应将字符串打印到控制台。但是,什么都没有发生 - 即终端保持空白,没有显示字符。

#initialise curses
import curses
stdscr=curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)

#write text
stdscr.addstr(0,0,'test')

#loop program so the terminal does not close
while 1:
    pass

我尝试将addstr拨打到While循环中,并使用包装器,但都没有解决问题。 发生了什么,我该如何解决这个问题?提前致谢!

I've recently installed the windows-curses module on my machine, via py -m pip install windows-curses run in an elevated command prompt.

I wrote the following code to test if it was working correctly. If it runs correctly, it should print the string test to the console. However, nothing happens - i.e the terminal remains blank, with no characters displayed.

#initialise curses
import curses
stdscr=curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)

#write text
stdscr.addstr(0,0,'test')

#loop program so the terminal does not close
while 1:
    pass

I've tried putting the addstr call inside the while loop, as well as using the wrapper, but neither resolved the issue.
What's going on, and how can I resolve this issue? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别把无礼当个性 2025-02-16 11:52:16

您必须刷新屏幕。当您要求输入时,例如window.getch()或调用window.refresh()直接进行物理屏幕更新。
尝试此片段:

#write text
stdscr.addstr(0, 0, 'test')

#loop program so the terminal does not close
while 1:
    c = stdscr.getch()
    key = curses.keyname(c)
    if key == b'q':
        break
    else:
        stdscr.addstr(1, 0, repr(key))

curses.endwin()

You have to refresh the screen. Curses does a physical screen update when you ask for input, e.g. with window.getch() or call window.refresh() directly.
Try this snippet:

#write text
stdscr.addstr(0, 0, 'test')

#loop program so the terminal does not close
while 1:
    c = stdscr.getch()
    key = curses.keyname(c)
    if key == b'q':
        break
    else:
        stdscr.addstr(1, 0, repr(key))

curses.endwin()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文