Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 2384

mozart-1.4.0-1mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>3.1 Toplevel Widgets and Widget Objects</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node6.html">- Up -</A></TD><TD><A href="node8.html#section.widgets-1.tickles">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.widgets-1.toplevel"><H2><A name="section.widgets-1.toplevel">3.1 Toplevel Widgets and Widget Objects</A></H2><P> A <A name="label35"></A><SPAN class="index">toplevel widget</SPAN> serves as the outermost <A name="label36"></A><EM>container</EM> for other widgets. It can be created from the class <A name="label38"></A><CODE>Tk<SPAN class="keyword">.</SPAN>toplevel</CODE> and can be initialized by applying it to a message with label <A name="label39"></A><SPAN class="index"><CODE>tkInit</CODE></SPAN>. An example is shown in <A href="node7.html#picture.widgets-1.toplevel">Figure&nbsp;3.1</A>. The features <A name="label40"></A><SPAN class="index"><CODE>width</CODE></SPAN> and <A name="label41"></A><SPAN class="index"><CODE>height</CODE></SPAN> of the message together with their values specify that the toplevel widget is 150 pixels wide and 50 pixels high. </P><P> </P><DIV id="picture.widgets-1.toplevel"><HR><P><A name="picture.widgets-1.toplevel"></A></P><P> </P><DIV align="center"><IMG alt="" src="toplevel-1.gif"></DIV><P> </P><DL class="anonymous"><DD class="code"><CODE>W={New&nbsp;Tk<SPAN class="keyword">.</SPAN>toplevel&nbsp;tkInit(width:150&nbsp;height:50)}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure&nbsp;3.1:</STRONG> Creating a toplevel widget.</P><HR></DIV><P> </P><P> Creating and initializing a widget object creates a graphical image for the widget object. We will refer to the graphical image just as the widget. Most often we will not distinguish between the object and its widget. A toplevel widget is special in that its graphical image appears immediately on the screen after the widget object has been initialized. Other widgets require to be managed by a so-called geometry manager before they appear on the screen. See <A href="node14.html#chapter.geometry">Chapter&nbsp;4</A> for a discussion of geometry managers. </P><P> A widget object can be sent a message with label <A name="label42"></A><SPAN class="index"><CODE>tk</CODE></SPAN> to change the appearance or behavior of its widget. For example, the <A name="label43"></A><SPAN class="index">background color</SPAN> of the toplevel widget <CODE>W</CODE> can be changed to purple by </P><DL class="anonymous"><DD class="code"><CODE>{W&nbsp;tk(configure&nbsp;background:purple)}</CODE></DD></DL><P> Additionally, a widget object understands messages that query its state. These will be discussed later. </P><P> <A name="label44"></A>A widget object can be closed by applying the object to the message <A name="label45"></A><SPAN class="index"><CODE>tkClose</CODE></SPAN>. Closing the widget object also destroys the widget displayed on the screen. <A href="node10.html#section.widgets-1.hierarchy">Section&nbsp;3.4</A> contains more details concerning how widget objects are closed. </P><P> The structure of messages with labels <A name="label46"></A><SPAN class="index"><CODE>tkInit</CODE></SPAN> and <A name="label47"></A><SPAN class="index"><CODE>tk</CODE></SPAN> depend on the particular widget under consideration. However, all of these messages share a common structure. The following section explains this structure and shows how to build messages such that they are understood by widgets. </P><P> <A name="label48"></A>Reference information on toplevel widgets can be found in <A href="../tcltk/TkCmd/toplevel.htm"><KBD>toplevel</KBD></A>. </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node6.html">- Up -</A></TD><TD><A href="node8.html#section.widgets-1.tickles">Next &gt;&gt;</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian&nbsp;Schulte</A><BR><SPAN class="version">Version 1.4.0 (20090610)</SPAN></ADDRESS></BODY></HTML>