Suppose you have this code and you just want to know how to implement draw() :
def draw(window, string): window.addstr(0, 0, string) window.refresh() draw(window, 'abcd') draw(window, 'xyz')
The simplest and “curse-ish” solution is, of course,
def draw(window, string): window.erase()
You may be tempted to write this instead:
def draw(window, string): window.clear()
But do not! Despite the friendly name, clear() is only valid for when you want the entire screen to be redrawn unconditionally , i.e. Flicker, The erase() function does the right thing without flickering.
Frédéric Hamidi offers the following solutions to erase only part (s) of the current window:
def draw(window, string): window.addstr(0, 0, string) window.clrtoeol()
A shorter and cleaner Python alternative would be
def draw(window, string): window.addstr(0, 0, '%-10s' % string)
Quuxplusone
source share