⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curses-functions.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.12.1 Functions </title>
<META NAME="description" CONTENT="6.12.1 Functions ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="curses-window-objects.html" tppabs="http://www.python.org/doc/current/lib/curses-window-objects.html">
<LINK REL="previous" href="module-curses.html" tppabs="http://www.python.org/doc/current/lib/module-curses.html">
<LINK REL="up" href="module-curses.html" tppabs="http://www.python.org/doc/current/lib/module-curses.html">
<LINK REL="next" href="curses-window-objects.html" tppabs="http://www.python.org/doc/current/lib/curses-window-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-curses.html" tppabs="http://www.python.org/doc/current/lib/module-curses.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-curses.html" tppabs="http://www.python.org/doc/current/lib/module-curses.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="curses-window-objects.html" tppabs="http://www.python.org/doc/current/lib/curses-window-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-curses.html" tppabs="http://www.python.org/doc/current/lib/module-curses.html">6.12 curses  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-curses.html" tppabs="http://www.python.org/doc/current/lib/module-curses.html">6.12 curses  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="curses-window-objects.html" tppabs="http://www.python.org/doc/current/lib/curses-window-objects.html">6.12.2 Window Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2>
<BR>
6.12.1 Functions 
</H2>

<P>
The module <tt class="module">curses</tt> defines the following exception:

<P>
<dl><dt><b><a name='l2h-1173'><tt class='exception'>error</tt></a></b>
<dd>
Exception raised when a curses library function returns an error.
</dl>

<P>
<b>Note:</b> Whenever <var>x</var> or <var>y</var> arguments to a function
or a method are optional, they default to the current cursor location.
Whenever <var>attr</var> is optional, it defaults to <tt class="constant">A_NORMAL</tt>.

<P>
The module <tt class="module">curses</tt> defines the following functions:

<P>
<dl><dt><b><a name='l2h-1174'><tt class='function'>baudrate</tt></a></b> ()
<dd>
Returns the output speed of the terminal in bits per second.  On
software terminal emulators it will have a fixed high value.
Included for historical reasons; in former times, it was used to 
write output loops for time delays and occasionally to change
interfaces depending on the line speed.
</dl>

<P>
<dl><dt><b><a name='l2h-1175'><tt class='function'>beep</tt></a></b> ()
<dd>
Emit a short attention sound.
</dl>

<P>
<dl><dt><b><a name='l2h-1176'><tt class='function'>can_change_color</tt></a></b> ()
<dd>
Returns true or false, depending on whether the programmer can change
the colors displayed by the terminal.
</dl>

<P>
<dl><dt><b><a name='l2h-1177'><tt class='function'>cbreak</tt></a></b> ()
<dd>
Enter cbreak mode.  In cbreak mode (sometimes called ``rare'' mode)
normal tty line buffering is turned off and characters are available
to be read one by one.  However, unlike raw mode, special characters
(interrupt, quit, suspend, and flow control) retain their effects on
the tty driver and calling program.  Calling first <tt class="function">raw()</tt>
then <tt class="function">cbreak()</tt> leaves the terminal in cbreak mode.
</dl>

<P>
<dl><dt><b><a name='l2h-1178'><tt class='function'>color_content</tt></a></b> (<var>color_number</var>)
<dd>
Returns the intensity of the red, green, and blue (RGB) components in
the color <var>color_number</var>, which must be between 0 and COLORS.  A
3-tuple is returned, containing the R,G,B values for the given color,
which will be between 0 (no component) and 1000 (maximum amount of
component).
</dl>

<P>
<dl><dt><b><a name='l2h-1179'><tt class='function'>color_pair</tt></a></b> (<var>color_number</var>)
<dd>
Returns the attribute value for displaying text in the specified
color.  This attribute value can be combined with
<tt class="constant">A_STANDOUT</tt>, <tt class="constant">A_REVERSE</tt>, and the other
<tt class="constant">A_*</tt> attributes.  <tt class="function">pair_number()</tt> is the counterpart to this function.
</dl>

<P>
<dl><dt><b><a name='l2h-1180'><tt class='function'>curs_set</tt></a></b> (<var>visibility</var>)
<dd>
Sets the cursor state.  <var>visibility</var> can be set to 0, 1, or 2, for
invisible, normal, or very visible.  If the terminal supports the
visibility requested, the previous cursor state is returned;
otherwise, an exception is raised.  On many terminals, the ``visible''
mode is an underline cursor and the ``very visible'' mode is a block cursor.
</dl>

<P>
<dl><dt><b><a name='l2h-1181'><tt class='function'>def_prog_mode</tt></a></b> ()
<dd>
Saves the current terminal mode as the ``program'' mode, the mode when
the running program is using curses.  (Its counterpart is the
``shell'' mode, for when the program is not in curses.)  Subsequent calls
to <tt class="function">reset_prog_mode()</tt> will restore this mode.
</dl>

<P>
<dl><dt><b><a name='l2h-1182'><tt class='function'>def_shell_mode</tt></a></b> ()
<dd>
Saves the current terminal mode as the ``shell'' mode, the mode when
the running program is not using curses.  (Its counterpart is the
``program'' mode, when the program is using curses capabilities.)
Subsequent calls
to <tt class="function">reset_shell_mode()</tt> will restore this mode.
</dl>

<P>
<dl><dt><b><a name='l2h-1183'><tt class='function'>delay_output</tt></a></b> (<var>ms</var>)
<dd>
Inserts an <var>ms</var> millisecond pause in output.  
</dl>

<P>
<dl><dt><b><a name='l2h-1184'><tt class='function'>doupdate</tt></a></b> ()
<dd>
Update the physical screen.  The curses library keeps two data
structures, one representing the current physical screen contents
and a virtual screen representing the desired next state.  The
<tt class="function">doupdate()</tt> ground updates the physical screen to match the
virtual screen.

<P>
The virtual screen may be updated by a <tt class="method">noutrefresh()</tt> call
after write operations such as <tt class="method">addstr()</tt> have been performed
on a window.  The normal <tt class="method">refresh()</tt> call is simply
<tt class="method">noutrefresh()</tt> followed by <tt class="function">doupdate()</tt>; if you have
to update multiple windows, you can speed performance and perhaps
reduce screen flicker by issuing <tt class="method">noutrefresh()</tt> calls on
all windows, followed by a single <tt class="function">doupdate()</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-1185'><tt class='function'>echo</tt></a></b> ()
<dd>
Enter echo mode.  In echo mode, each character input is echoed to the
screen as it is entered.  
</dl>

<P>
<dl><dt><b><a name='l2h-1186'><tt class='function'>endwin</tt></a></b> ()
<dd>
De-initialize the library, and return terminal to normal status.
</dl>

<P>
<dl><dt><b><a name='l2h-1187'><tt class='function'>erasechar</tt></a></b> ()
<dd>
Returns the user's current erase character.  Under Unix operating
systems this is a property of the controlling tty of the curses
program, and is not set by the curses library itself.
</dl>

<P>
<dl><dt><b><a name='l2h-1188'><tt class='function'>filter</tt></a></b> ()
<dd>
The <tt class="function">filter()</tt> routine, if used, must be called before
<tt class="function">initscr()</tt> is  called.  The effect is that, during those
calls, LINES is set to 1; the capabilities clear, cup, cud, cud1,
cuu1, cuu, vpa are disabled; and the home string is set to the value of cr.
The effect is that the cursor is confined to the current line, and so
are screen updates.  This may be used for enabling cgaracter-at-a-time 
line editing without touching the rest of the screen.
</dl>

<P>
<dl><dt><b><a name='l2h-1189'><tt class='function'>flash</tt></a></b> ()
<dd>
Flash the screen.  That is, change it to reverse-video and then change
it back in a short interval.  Some people prefer such as `visible bell'
to the audible attention signal produced by <tt class="function">beep()</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-1190'><tt class='function'>flushinp</tt></a></b> ()
<dd>
Flush all input buffers.  This throws away any  typeahead  that  has
been typed by the user and has not yet been processed by the program.
</dl>

<P>
<dl><dt><b><a name='l2h-1191'><tt class='function'>getmouse</tt></a></b> ()
<dd>
After <tt class="method">getch()</tt> returns <tt class="constant">KEY_MOUSE</tt> to signal a mouse
event, this method should be call to retrieve the queued mouse event,
represented as a 5-tuple
<code>(<var>id</var>, <var>x</var>, <var>y</var>, <var>z</var>, <var>bstate</var>)</code>.
<var>id</var> is an ID value used to distinguish multiple devices,
and <var>x</var>, <var>y</var>, <var>z</var> are the event's coordinates.  (<var>z</var>
is currently unused.).  <var>bstate</var> is an integer value whose bits
will be set to indicate the type of event, and will be the bitwise OR
of one or more of the following constants, where <var>n</var> is the button
number from 1 to 4:
<tt class="constant">BUTTON<var>n</var>_PRESSED</tt>,
<tt class="constant">BUTTON<var>n</var>_RELEASED</tt>,
<tt class="constant">BUTTON<var>n</var>_CLICKED</tt>,
<tt class="constant">BUTTON<var>n</var>_DOUBLE_CLICKED</tt>,
<tt class="constant">BUTTON<var>n</var>_TRIPLE_CLICKED</tt>,
<tt class="constant">BUTTON_SHIFT</tt>,
<tt class="constant">BUTTON_CTRL</tt>,
<tt class="constant">BUTTON_ALT</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-1192'><tt class='function'>getsyx</tt></a></b> ()
<dd>
Returns the current coordinates of the virtual screen cursor in y and
x.  If leaveok is currently true, then -1,-1 is returned.
</dl>

<P>
<dl><dt><b><a name='l2h-1193'><tt class='function'>getwin</tt></a></b> (<var>file</var>)
<dd>
Reads window related data stored in the file by an earlier
<tt class="function">putwin()</tt> call.  The routine then creates and initializes a
new window using that data, returning the new window object.
</dl>

<P>
<dl><dt><b><a name='l2h-1194'><tt class='function'>has_colors</tt></a></b> ()
<dd>
Returns true if the terminal can display colors; otherwise, it
returns false. 
</dl>

<P>
<dl><dt><b><a name='l2h-1195'><tt class='function'>has_ic</tt></a></b> ()
<dd>
Returns true if the terminal has insert- and delete- character
capabilities.  This function is included for historical reasons only,
as all modern software terminal emulators have such capabilities.
</dl>

<P>
<dl><dt><b><a name='l2h-1196'><tt class='function'>has_il</tt></a></b> ()
<dd>
Returns true if the terminal has insert- and
delete-line  capabilities,  or  can  simulate  them  using
scrolling regions. This function is included for historical reasons only,
as all modern software terminal emulators have such capabilities.
</dl>

<P>
<dl><dt><b><a name='l2h-1197'><tt class='function'>has_key</tt></a></b> (<var>ch</var>)
<dd>
Takes a key value <var>ch</var>, and returns true if the current terminal
type recognizes a key with that value.
</dl>

<P>
<dl><dt><b><a name='l2h-1198'><tt class='function'>halfdelay</tt></a></b> (<var>tenths</var>)
<dd>
Used for half-delay mode, which is similar to cbreak mode in that
characters typed by the user are immediately available to the program.
However, after blocking for <var>tenths</var> tenths of seconds, an
exception is raised if nothing has been typed.  The value of
<var>tenths</var> must be a number between 1 and 255.  Use <tt class="function">nocbreak()</tt> to
leave half-delay mode.
</dl>

<P>
<dl><dt><b><a name='l2h-1199'><tt class='function'>init_color</tt></a></b> (<var>color_number, r, g, b</var>)
<dd>
Changes the definition of a color, taking the number of the color to
be changed followed by three RGB values (for the amounts of red,
green, and blue components).  The value of <var>color_number</var> must be
between 0 and COLORS.  Each of <var>r</var>, <var>g</var>, <var>b</var>, must be a
value between 0 and 1000.  When <tt class="function">init_color()</tt> is used, all
occurrences of that color on the screen immediately change to the new
definition.  This function is a no-op on most terminals; it is active
only if <tt class="function">can_change_color()</tt> returns 1.
</dl>

<P>
<dl><dt><b><a name='l2h-1200'><tt class='function'>init_pair</tt></a></b> (<var>pair_number, fg, bg</var>)
<dd>
Changes the definition of a color-pair.  It takes three arguments: the
number of the color-pair to be changed, the foreground color number,
and the background color number.  The value of <var>pair_number</var> must
be between 1 and COLOR_PAIRS-1 (the 0 color pair is wired to white on
black and cannot be changed).  The value of <var>fg</var> and <var>bg</var>
arguments must be between 0 and COLORS.  If the color-pair was
previously initialized, the screen is refreshed and all occurrences of
that color-pair are changed to the new definition.
</dl>

<P>
<dl><dt><b><a name='l2h-1201'><tt class='function'>initscr</tt></a></b> ()
<dd>
Initialize the library. Returns a <tt class="class">WindowObject</tt> which represents
the whole screen.
</dl>

<P>
<dl><dt><b><a name='l2h-1202'><tt class='function'>isendwin</tt></a></b> ()
<dd>
Returns true if <tt class="function">endwin()</tt> has been called (that is, the 
curses library has been deinitialized).
</dl>

<P>
<dl><dt><b><a name='l2h-1203'><tt class='function'>keyname</tt></a></b> (<var>k</var>)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -