212.html

来自「Python Ebook Python&XML」· HTML 代码 · 共 151 行

HTML
151
字号

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -&gt; Tkinter Widgets</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> &gt; <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> &gt; <a href="206.html" class="navtitle">15. Tkinter</a> &gt; <span class="nonavtitle">Tkinter Widgets</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="211.html" title="Handling Tkinter Events"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=212" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="212.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="213.html" title="Designing Applications"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A49%3A09+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162148037071157167172241241</font><a href="read7.asp?bookname=0672319942&snode=212&now=5%2F31%2F2002+4%3A49%3A09+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
				<h3>




Tkinter Widgets</h3>
				<p>The typical Tkinter distribution contains a basic set of 15 widgets, and some extra classes.</p>

				<P>The Tkinter reference that I present in this chapter only shows a small set of methods and attributes for each one of the available widgets. This list is provided just to give you some idea of what you can do with each one of the widgets, and it is doesn't have the intention to be a complete guide. If you need to go further in this topic, I suggest you look at the Tkinter resources pages that I list at the end of this chapter.</P>

				
					<H4>Widget Standard Options</H4>
					<p>Almost all widgets have access to a set of standard attributes that define special characteristics for each one of them, including color definitions and font types. The value for each one of these attributes can be determined at the creation time as</p>

					<prE>
						
mylabel = Label(win, width=40)

					</PRE>

					<p>Or, if you prefer, you can also <a naME="idx1073748619"></A>
						<A name="idx1073748620"></a>
						<a name="idx1073748621"></a>
						<a name="idx1073748622"></a>
						<a naMe="idx1073748623"></a>define (or change) the values at the execution time using the <Tt clAss="monofont">configure</tt> method.</P>

					<pre>
						
mylabel.configure(width=40)

					</PRE>

					<P>The previous examples use <i>key/value</i> pairs to define the attribute values, but you can also use <a nAME="idx1073748624"></A>dictionaries to easily inform multiple attributes at once.</p>

					<pre>
						
mysize = { "height"=2, "width"=40}
mylabel.configure(mysize)

					</PRE>

					<P>Support for using dictionaries here is really for backward compatibility for programs written before Python 1.4 (which didn't support keyword arguments). It is not a good idea to use it with the latest versions of Python. The third way of changing properties is with</p>

					<pre>
						
mylabel['height'] = 2

					</PRE>

					<P>Next, I list common properties that are defined for all Tkinter widgets.</p>

					
						<h5>


height</h5>
						<p>In buttons, labels, and text widgets, this attribute defines the height in number of characters. In all other widgets, it defines the height in pixels.</p>

					
					
						<h5>

width</h5>
						<p>In buttons, labels, and text widgets, this attribute defines the width in number of characters. In all other widgets, it defines the width in pixels.</p>

					
					
						<h5>
							<tt class="monofont">background(bg)</tt> and <tT clAss="monofont">foreground(fg)</tT>
						</h5>
						<p>These attributes define the background and foreground (text) colors for a specific widget. It can be either a color name or a explicit hexadecimal notation RGB starting with <tt ClasS="monofont">#.</TT> It is usually used in one of the following formats: <Tt claSS="monofont">"#RRGGBB",</TT>
							<tt clASS="monofont">"#RGB",</Tt> and <tt cLASS="monofont">"#RRRRGGGGBBBB",</tt> depending on the number of colors allowed by your system.</p>

						<p>If you are using either a Windows or a Macintosh system, the table that contains the available color names is already built into your system.</p>

						<p>The following constants define the system colors that you can use within your Windows system.</p>

						<pre>
							
SystemActiveBorder, SystemActiveCaption, SystemAppWorkspace,
SystemBackground, SystemButtonFace, SystemButtonHighlight,
SystemButtonShadow, SystemButtonText, SystemCaptionText, SystemDisabledText,
SystemHighlight, SystemHighlightText, SystemInactiveBorder,
SystemInactiveCaption, SystemInactiveCaptionText, SystemMenu, SystemMenuText,
SystemScrollbar, SystemWindow, SystemWindowFrame, SystemWindowText.

						</pre>

						<p>Note that you can change the colors at any time by editing the control panel settings.</p>

						<p>The same concept goes for Mac systems. The available list of <a namE="idx1073748625"></a>
							<a Name="idx1073748626"></A>
							<a namE="idx1073748627"></a>color names for the Macintosh platform is as follows:</p>

						<p><TABLe borDER="1" CellsPACIng="0" ceLLPAdding="1" width="100%">
<colgroup alIgn="left" Span="2">
<Tr valIgn="top">
<tD>
<FONt sizE="2">SystemButtonFace</FONt></td>
<tD>
<FONt sizE="2">SystemMenuActive</FONt></td>
</tr>
<tr valign="top">
<td>
<font sIze="2">SystemButtonFrame</Font></Td>
<td>
<fOnt sIZE="2">SystemMenuActiveText</Font></tD>
</TR>
<Tr valIGN="top">
<Td>
<fonT SIZe="2">SystemButtonText</font></td>
<td>
<font size="2">SystemMenuDisabled</fonT></td>
</Tr>
<tr ValigN="top">
<td>
<fONT Size="2">SystemHighlight</fONT></Td>
<td>
<fONT Size="2">SystemMenuText</fONT></Td>
</tr>
<tr valign="top">
<td>
<font sizE="2">SystemHighlightText</foNt></td>
<Td>
<fonT sizE="2">SystemWindowBody</FONt></td>
</tR>
<TR ValigN="top">
<TD>
<Font sIZE="2">SystemMenu<A name="idx1073748628"></a>
											<a name="idx1073748629"></a>
											<a name="idx1073748630"></a>
										</fonT></td>
<Td>
<foNt sizE="2">

⌨️ 快捷键说明

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