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

📄 124.html

📁 Tcl 语言的入门级图书
💻 HTML
字号:
<HTML><TITLE>Widget Characteristics: Colors</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Colors</H1></A>


<P>  Colors are represented as three hexadecimal numbers that determine their
red, green, and blue parts.  Each of these three numbers can be up to four
hexadecimal digits.  You can specify fewer digits if you are consistent and do
it for all three numbers.  When you specify fewer the number is padded with
0s on the right.  A color specification consists of the character "#"
followed by these numbers in the order: red, green, blue.  For example,
<TT>#00ff00</TT> is a specification for pure green.

<P>  Using hexadecimal numbers to identify colors is not much fun.  Figure 12.4a
shows a window displayed by a script designed to help.  Move the sliders in
this window to change the red, green, and blue components of the color
patch on the left.  A color specification for that color appears below.
This script appears below in 
<A HREF="NotHere.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/NotHere.html">Scale</A> where there is an explanation
of how it works.  It is also available on line as Script S15.11a.

<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 12.4a: Choosing a color interactively.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F12x4a.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F12x4a.JPG">
</TD></TR>
</TABLE></CENTER><P>

<P>  Here is a list of color options that can be used with most built-in 
widget types:

<P><CENTER><TABLE BORDER><TR><TD><DL>

<P> <DT><STRONG><PRE><NAME=#S12.4background>-background</A></PRE></STRONG><DD> The widget's background color. This option
is sometimes written <TT><NAME=#S12.4bg>-bg</A>.</TT>

<P>  <DT><STRONG><PRE><NAME=#S12.4foreground>-foreground</A></PRE></STRONG><DD> The widget's foreground color.  (Frame widgets
have no foreground color.)  This option is sometimes written
<TT><NAME=#S12.4fg>-fg</A>.</TT>

<P> <DT><STRONG><PRE><NAME=#S12.4hghlghtclr>-highlightcolor</A></PRE></STRONG><DD> The widget's highlight color is the color
given to a small highlight border around the edge whenever the widget has the
focus.

<P> <DT><STRONG><PRE><NAME=#S12.4hghlghtbckgrnd>-highlightbackground</A></PRE></STRONG><DD> The widget's highlight background color
is the color given to a small highlight border around the edge whenever the
widget does not have the focus.

<P> <DT><STRONG><PRE><NAME=#S12.4hghlghtthcknss>-highlightthickness</A></PRE></STRONG><DD> Not exactly a color option.  Use this
option to control the width of the small highlight border.  A value of 0 means
there will be no visible color change when the widget's focus status changes.
The default value of this option is 0 for widgets whose default configuration
has no use for the focus.  When specifying a nonzero value, you are
specifying a screen distance.

</DL></TD></TR></TABLE></CENTER></P>

<P>  Except for <TT>-highlightthickness</TT>, all these options require
a color specification as a value.  The numeric specification described above
will always work.  Often, you can get away with an ordinary color name such as
white, black, red, green, blue, and so forth.

<P>  There are many other color-related options that are widget specific.  Your
on-line manual and a little experimentation are the best sources of information
about new or unusual widgets.

<P>  <P><A NAME="12.4a">
<STRONG>Exercise 12.4a</STRONG> </A><DL><DD>
  Create and pack a square frame with a white
background. <P>
<A HREF="12.8.html#Sol12.4a" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.8.html#Sol12.4a">Solution</A></DL>


<P>  <P><A NAME="12.4b">
<STRONG>Exercise 12.4b</STRONG> </A><DL><DD>
 Finish the following loop to test several possible color
names to see if Tk recognizes them.

<PRE>
foreach C <CITE>LIST_OF_COLOR_NAMES</CITE> { 
   <CITE>...</CITE> 
}
</PRE>

Each color name should create a square frame of that color or a label
whose text is an unusable color name.
<P>
<A HREF="12.8.html#Sol12.4b" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.8.html#Sol12.4b">Solution</A></DL>


<P> <P><A NAME="12.4c">
<STRONG>Exercise 12.4c</STRONG> </A><DL><DD>
   Finish implementing this procedure

<PRE>
proc box {Parent Color {Shape ""}} { ... }
</PRE>

so that it creates a rectangle of the given <TT>Color</TT> and with the given
<TT>Parent</TT> widget.  If the <TT>Shape</TT> argument is empty the rectangle should
be a square with one centimeter sides.

<P>   The <TT>Shape</TT> argument can have two nonempty values "h" and "v."
When <TT>Shape</TT> is "h," your rectangle should be 3 centimeters long and 1
centimeter high.  When <TT>Shape</TT> is "v," your rectangle should be 1 centimeter
long and 3 centimeters high.

<P>   The <TT>box</TT> procedure must generate a unique name for the widget
it creates.  Like Tk's built-in widget makers, it should return that
name as it finishes.  Here is an example use of <TT>box</TT>:

<PRE>
% box . red
.red1
% pack .red1
</PRE>
<P>
<A HREF="12.8.html#Sol12.4c" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.8.html#Sol12.4c">Solution</A></DL>


<!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="12.3.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.3.html">section</A><WBR>
<STRONG>Next</STRONG>
<A HREF="12.5.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.5.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="12.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
 </NOBR></FONT></CENTER></BODY></HTML>


⌨️ 快捷键说明

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