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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -