Python Curses window.getch() returns wrong value -


why when run code box.getch() returns wrong value , when change box.getch() screen.getch() returns right value? i've been looking on internet , there no 1 saying getch() works screens. if press 1 of arrows returns 27 chr of esc. (this code should print character untill user presses esc...)

import curses screen = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() screen.keypad( 1 ) curses.init_pair(1,curses.color_black, curses.color_cyan) highlighttext = curses.color_pair( 1 ) normaltext = curses.a_normal screen.border( 0 ) curses.curs_set( 0 ) box = curses.newwin( 22, 64, 1, 1 ) box.box() box.addstr( 14, 3, "you have pressed: ")  screen.refresh() box.refresh()  x = box.getch() while x != 27:     box.erase()     box.addstr( 14, 3, "you have pressed: " + str(x) )     screen.border( 0 )     box.border( 0 )     screen.refresh()     box.refresh()     x = box.getch()  curses.endwin() exit() 

the answer (see bug refresh in python curses) add box.keypad(1). there few lines unnecessary - marked in example:

     import curses     screen = curses.initscr()     curses.noecho()     curses.cbreak()     curses.start_color()     screen.keypad( 1 )    # delete line     curses.init_pair(1,curses.color_black, curses.color_cyan)     highlighttext = curses.color_pair( 1 )     normaltext = curses.a_normal     screen.border( 0 )     curses.curs_set( 0 )     box = curses.newwin( 22, 64, 1, 1 )     box.keypad( 1 )     box.box()     box.addstr( 14, 3, "you have pressed: ")      screen.refresh()    # delete line     box.refresh()      x = box.getch()     while x != 27:         box.erase()         box.addstr( 14, 3, "you have pressed: " + str(x) )         screen.border( 0 )         box.border( 0 )         screen.refresh()  # delete line         box.refresh()     # delete line         x = box.getch()      curses.endwin()     exit() 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -