6.12.2 Window Objects

Window objects, as returned by initscr() and newwin() above, have the following methods:

refresh ()
Update the display immediately (sync actual screen with previous drawing/deleting methods).

nooutrefresh ()
Mark for refresh but wait.

mvwin (new_y, new_x)
Move the window so its upper-left corner is at (new_y, new_x).

move (new_y, new_x)
Move cursor to (new_y, new_x).

subwin ([nlines, ncols,] begin_y, begin_y)
Return a sub-window, whose upper-left corner is at (begin_y, begin_x), and whose width/height is ncols/nlines.

By default, the sub-window will extend from the specified position to the lower right corner of the window.

addch ([y, x,] ch[, attr])
Note: A character means a C character (i.e., an ASCII code), rather then a Python character (a string of length 1). (This note is true whenever the documentation mentions a character.)

Paint character ch at (y, x) with attributes attr, overwriting any character previously painter at that location. By default, the character position and attributes are the current settings for the window object.

insch ([y, x,] ch[, attr])
Paint character ch at (y, x) with attributes attr, moving the line from position x right by one character.

delch ([x, y])
Delete any character at (y, x).

echochar (ch[, attr])
Add character ch with attribute attr, and immediately call refresh.

addstr ([y, x,] str[, attr])
Paint string str at (y, x) with attributes attr, overwriting anything previously on the display.

attron (attr)
Turn on attribute attr.

attroff (attr)
Turn off attribute attr.

setattr (attr)
Set the current attributes to attr.

standend ()
Turn off all attributes.

standout ()
Turn on attribute A_STANDOUT.

border ([ls[, rs[, ts[, bs[, tl[, tr[, bl[, br]]]]]]]])
Draw a border around the edges of the window. Each parameter specifies the character to use for a specific part of the border; see the table below for more details. The characters must be specified as integers; using one-character strings will cause TypeError to be raised.

Note: A 0 value for any parameter will cause the default character to be used for that parameter. Keyword parameters can not be used. The defaults are listed in this table:

Parameter  Description  Default value 
ls Left side ACS_VLINE
rs Right side ACS_VLINE
ts Top ACS_HLINE
bs Bottom ACS_HLINE
tl Upper-left corner ACS_ULCORNER
tr Upper-right corner ACS_URCORNER
bl Bottom-left corner ACS_BLCORNER
br Bottom-right corner ACS_BRCORNER

box ([vertch, horch])
Similar to border(), but both ls and rs are vertch and both ts and bs are horch. The default corner characters are always used by this function.

hline ([y, x,] ch, n)
Display a horizontal line starting at (y, x) with length n consisting of the character ch.

vline ([y, x,] ch, n)
Display a vertical line starting at (y, x) with length n consisting of the character ch.

erase ()
Clear the screen.

deletln ()
Delete the line under the cursor. All following lines are moved up by 1 line.

insertln ()
Insert a blank line under the cursor. All following lines are moved down by 1 line.

getyx ()
Return a tuple (y, x) of current cursor position.

getbegyx ()
Return a tuple (y, x) of co-ordinates of upper-left corner.

getmaxyx ()
Return a tuple (y, x) of the height and width of the window.

clear ()
Like erase(), but also causes the whole screen to be repainted upon next call to refresh().

clrtobot ()
Erase from cursor to the end of the screen: all lines below the cursor are deleted, and then the equivalent of clrtoeol() is performed.

clrtoeol ()
Erase from cursor to the end of the line.

scroll ([lines = 1])
Scroll the screen upward by lines lines.

touchwin ()
Pretend the whole window has been changed, for purposes of drawing optimizations.

touchline (start, count)
Pretend count lines have been changed, starting with line start.

getch ([x, y])
Get a character. Note that the integer returned does not have to be in ASCII range: function keys, keypad keys and so on return numbers higher then 256. In no-delay mode, an exception is raised if there is no input.

getstr ([x, y])
Read a string from the user, with primitive line editing capacity.

inch ([x, y])
Return the character at the given position in the window. The bottom 8 bits are the character proper, and upper bits are the attributes.

clearok (yes)
If yes is 1, the next call to refresh() will clear the screen completely.

idlok (yes)
If called with yes equal to 1, curses will try and use hardware line editing facilities. Otherwise, line insertion/deletion are disabled.

leaveok (yes)
If yes is 1, cursor is left where it is, instead of being at ``cursor position.'' This reduces cursor movement where possible. If possible it will be made invisible.

If yes is 0, cursor will always be at ``cursor position'' after an update.

setscrreg (top, bottom)
Set the scrolling region from line top to line bottom. All scrolling actions will take place in this region.

keypad (yes)
If yes is 1, escape sequences generated by some keys (keypad, function keys) will be interpreted by curses.

If yes is 0, escape sequences will be left as is in the input stream.

nodelay (yes)
If yes is 1, getch() will be non-blocking.

notimeout (yes)
If yes is 1, escape sequences will not be timed out.

If yes is 0, after a few milliseconds, an escape sequence will not be interpreted, and will be left in the input stream as is.


Send comments on this document to python-docs@python.org.