-
-
Save myano/1055442 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python | |
import curses | |
import curses.textpad | |
import time | |
stdscr = curses.initscr() | |
#curses.noecho() | |
#curses.echo() | |
begin_x = 20 | |
begin_y = 7 | |
height = 5 | |
width = 40 | |
win = curses.newwin(height, width, begin_y, begin_x) | |
tb = curses.textpad.Textbox(win) | |
text = tb.edit() | |
curses.addstr(4,1,text.encode('utf_8')) | |
#hw = "Hello world!" | |
#while 1: | |
# c = stdscr.getch() | |
# if c == ord('p'): | |
# elif c == ord('q'): break # Exit the while() | |
# elif c == curses.KEY_HOME: x = y = 0 | |
curses.endwin() |
If your terminal gets completely hosed, you can usually run "tset" which means Terminal reSET.
How you can avoid keyboard interrupt problems: catch it, and reset the curses variables.
def reset(screen):
curses.nocbreak()
screen.keypad(0)
curses.echo()
curses.endwin()
try:
#your code
#if it terminates, call `reset(screen)` here too.
except KeyboardInterrupt:
reset(screen)
exit()
if c == ord('p'): print hw
?
Can someone explains me the usage of curses.wrapper()? It looks pretty simple.
Quick tip, if you exit without cleaning up and your terminal is in a wonky state, just run stty sane
and it'll be good as new 😀
When I try to use the curses. I use UBUNTU and the code returns this error:
Traceback (most recent call last):
File "/home/andre/Desktop/Python - Programas/exemplo curses.py", line 4, in
stdscr = curses.initscr()
File "/usr/lib/python3.6/curses/init.py", line 30, in initscr
fd=_sys.stdout.fileno())
_curses.error: setupterm: could not find terminal
Someone knows why this occurs?
Thanks so much ;)