简体   繁体   English

Ncurses,python和OSX Lion

[英]Ncurses, python, and OSX Lion

I'm new to nurses, and trying it out on my OSX Lion with some python code. 我是护士的新手,并在我的OSX Lion上尝试了一些python代码。 I've ran across a weird bug, and I don't know what I'm doing wrong. 我遇到了一个奇怪的错误,我不知道我做错了什么。 I've Googled extensively, and can't find a similar issue, even in linux. 我已经广泛搜索,即使在linux中也找不到类似的问题。 I've selectively removed lines to see if one of them is an issue, also. 我有选择地删除了行,看看其中一行是否也是一个问题。 When I run the code below, I get nothing. 当我运行下面的代码时,我什么都没得到。 No menu, and my terminal is messed up, if I hit enter, you see what I get in the picture below. 没有菜单,我的终端搞砸了,如果我点击进入,你会看到我在下面的图片中看到的内容。 I have to type a reset to make it work well again. 我必须键入一个reset以使其再次正常工作。 Can anyone give me suggestions, or point me in the direction where to look? 任何人都可以给我建议,或指向我的方向去看? I would really appreciate it. 我真的很感激。 Thanks. 谢谢。

Script: 脚本:

import curses

screen = curses.initscr()   # Init curses
curses.noecho()             # Suppress key output to screen
curses.curs_set(0)          # remove cursor from screen
screen.keypad(1)            # set mode when capturing keypresses

top_pos = 12
left_pos = 12
screen.addstr(top_pos, left_pos, "This is a String")

Result: 结果:

截图

BTW, I'm using the default python and libs in Lion, no macports. 顺便说一句,我在Lion中使用默认的python和libs,没有macports。 I'd like to use the native libraries, if possible . 如果可能的话 ,我想使用本机库。

You have 2 problems. 你有2个问题。

After adding the string to the screen with addstr you don't tell it to refresh the screen. 使用addstr将字符串添加到屏幕后,您不要告诉它刷新屏幕。 Add this after the call to addstr: 在调用addstr之后添加:

screen.refresh()

You need to call endwin() at the end of you program to reset the terminal. 您需要在程序结束时调用endwin()来重置终端。 Add this to the end of your program: 将其添加到程序的末尾:

curses.endwin()

That said, after making those 2 changes when you run your program it will appear to do nothing because after displaying the string on the screen curses exits and returns the screen to the state before you ran the program. 也就是说,在运行程序后进行这两项更改之后,它似乎什么都不做,因为在屏幕上显示字符串后会弹出退出并将屏幕返回到运行程序之前的状态。

Add this before the call to endwin(): 在调用endwin()之前添加它:

screen.getch()

Then it will wait for you press a key before exiting. 然后它会在退出前等你按一个键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM