📄 curses-textpad-objects.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.13.1 Textbox objects </title>
<META NAME="description" CONTENT="6.13.1 Textbox objects ">
<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="previous" href="module-curses.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.html">
<LINK REL="up" href="module-curses.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.html">
<LINK REL="next" href="module-curses.wrapper.html" tppabs="http://www.python.org/doc/current/lib/module-curses.wrapper.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-curses.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.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.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.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="module-curses.wrapper.html" tppabs="http://www.python.org/doc/current/lib/module-curses.wrapper.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.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.html">6.13 curses.textpad </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-curses.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.html">6.13 curses.textpad </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-curses.wrapper.html" tppabs="http://www.python.org/doc/current/lib/module-curses.wrapper.html">6.14 curses.wrapper </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H2>
<BR>
6.13.1 Textbox objects
</H2>
<P>
You can instantiate a <tt class="class">Textbox</tt> object as follows:
<P>
<dl><dt><b><a name='l2h-1307'><tt class='class'>Textbox</tt></a></b> (<var>win</var>)
<dd>
Return a textbox widget object. The <var>win</var> argument should be a
curses <tt class="class">WindowObject</tt> in which the textbox is to be contained.
The edit cursor of the textbox is initially located at the upper left
hand corner of the containin window, with coordinates <code>(0, 0)</code>.
The instance's <tt class="member">stripspaces</tt> flag is initially on.
</dl>
<P>
<tt class="class">Textbox</tt> objects have the following methods:
<P>
<dl><dt><b><a name='l2h-1308'><tt class='method'>edit</tt></a></b> (<big>[</big><var>validator</var><big>]</big>)
<dd>
This is the entry point you will normally use. It accepts editing
keystrokes until one of the termination keystrokes is entered. If
<var>validator</var> is supplied, it must be a function. It will be called
for each keystroke entered with the keystroke as a parameter; command
dispatch is done on the result. This method returns the window
contents as a string; whether blanks in the window are included is
affected by the <tt class="member">stripspaces</tt> member.
</dl>
<P>
<dl><dt><b><a name='l2h-1309'><tt class='method'>do_command</tt></a></b> (<var>ch</var>)
<dd>
Process a single command keystroke. Here are the supported special
keystrokes:
<P>
<table border align="center" style="border-collapse: collapse">
<thead>
<tr class="tableheader">
<th align="left"><b>Keystroke</b> </th>
<th align="left"><b>Action</b> </th>
</thead>
<tbody valign='baseline'>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-A</tt></td>
<td align="left">Go to left edge of window.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-B</tt></td>
<td align="left">Cursor left, wrapping to previous line if appropriate.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-D</tt></td>
<td align="left">Delete character under cursor.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-E</tt></td>
<td align="left">Go to right edge (stripspaces off) or end of line (stripspaces on).</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-F</tt></td>
<td align="left">Cursor right, wrapping to next line when appropriate.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-G</tt></td>
<td align="left">Terminate, returning the window contents.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-H</tt></td>
<td align="left">Delete character backward.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-J</tt></td>
<td align="left">Terminate if the window is 1 line, otherwise insert newline.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-K</tt></td>
<td align="left">If line is blank, delete it, otherwise clear to end of line.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-L</tt></td>
<td align="left">Refresh screen.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-N</tt></td>
<td align="left">Cursor down; move down one line.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-O</tt></td>
<td align="left">Insert a blank line at cursor location.</td>
<tr><td align="left" valign="baseline"><tt class="constant">Ctrl-P</tt></td>
<td align="left">Cursor up; move up one line.</td></tbody>
</table>
<P>
Move operations do nothing if the cursor is at an edge where the
movement is not possible. The following synonyms are supported where
possible:
<P>
<table border align="center" style="border-collapse: collapse">
<thead>
<tr class="tableheader">
<th align="left"><b>Constant</b> </th>
<th align="left"><b>Keystroke</b> </th>
</thead>
<tbody valign='baseline'>
<tr><td align="left" valign="baseline"><tt class="constant">KEY_LEFT</tt></td>
<td align="left"><kbd>Ctrl-B</kbd></td>
<tr><td align="left" valign="baseline"><tt class="constant">KEY_RIGHT</tt></td>
<td align="left"><kbd>Ctrl-F</kbd></td>
<tr><td align="left" valign="baseline"><tt class="constant">KEY_UP</tt></td>
<td align="left"><kbd>Ctrl-P</kbd></td>
<tr><td align="left" valign="baseline"><tt class="constant">KEY_DOWN</tt></td>
<td align="left"><kbd>Ctrl-N</kbd></td>
<tr><td align="left" valign="baseline"><tt class="constant">KEY_BACKSPACE</tt></td>
<td align="left"><kbd>Ctrl-h</kbd></td></tbody>
</table>
<P>
All other keystrokes are treated as a command to insert the given
character and move right (with line wrapping).
</dl>
<P>
<dl><dt><b><a name='l2h-1310'><tt class='method'>gather</tt></a></b> ()
<dd>
This method returns the window contents as a string; whether blanks in
the window are included is affected by the <tt class="member">stripspaces</tt>
member.
</dl>
<P>
<dl><dt><b><a name='l2h-1311'><tt class='member'>stripspaces</tt></a></b>
<dd>
This data member is a flag which controls the interpretation of blanks in
the window. When it is on, trailing blanks on each line are ignored;
any cursor motion that would land the cursor on a trailing blank goes
to the end of that line instead, and trailing blanks are stripped when
the window contents is gathered.
</dl>
<P>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-curses.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.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.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.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="module-curses.wrapper.html" tppabs="http://www.python.org/doc/current/lib/module-curses.wrapper.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.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.html">6.13 curses.textpad </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-curses.textpad.html" tppabs="http://www.python.org/doc/current/lib/module-curses.textpad.html">6.13 curses.textpad </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-curses.wrapper.html" tppabs="http://www.python.org/doc/current/lib/module-curses.wrapper.html">6.14 curses.wrapper </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -