| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="node724.html" /> |
| 13 | <link rel="prev" href="node722.html" /> |
| 14 | <link rel="parent" href="node722.html" /> |
| 15 | <link rel="next" href="node724.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>16.1.6.1 Setting Options </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="16.1.6 Handy Reference" |
| 25 | href="node722.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="16.1.6 Handy Reference" |
| 28 | href="node722.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="16.1.6.2 The Packer" |
| 31 | href="node724.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="node722.html">16.1.6 Handy Reference</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="node722.html">16.1.6 Handy Reference</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="node724.html">16.1.6.2 The Packer</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H3><A NAME="SECTION0018161000000000000000"></A><A NAME="tkinter-setting-options"></A> |
| 56 | <BR> |
| 57 | 16.1.6.1 Setting Options |
| 58 | |
| 59 | </H3> |
| 60 | |
| 61 | <P> |
| 62 | Options control things like the color and border width of a widget. |
| 63 | Options can be set in three ways: |
| 64 | |
| 65 | <P> |
| 66 | <DL> |
| 67 | <DT><STRONG>At object creation time, using keyword arguments</STRONG></DT> |
| 68 | <DD>: |
| 69 | <div class="verbatim"><pre> |
| 70 | fred = Button(self, fg = "red", bg = "blue") |
| 71 | </pre></div> |
| 72 | </DD> |
| 73 | <DT><STRONG>After object creation, treating the option name like a dictionary index</STRONG></DT> |
| 74 | <DD>: |
| 75 | <div class="verbatim"><pre> |
| 76 | fred["fg"] = "red" |
| 77 | fred["bg"] = "blue" |
| 78 | </pre></div> |
| 79 | </DD> |
| 80 | <DT><STRONG>Use the config() method to update multiple attrs subsequent to |
| 81 | object creation</STRONG></DT> |
| 82 | <DD>: |
| 83 | <div class="verbatim"><pre> |
| 84 | fred.config(fg = "red", bg = "blue") |
| 85 | </pre></div> |
| 86 | </DD> |
| 87 | </DL> |
| 88 | |
| 89 | <P> |
| 90 | For a complete explanation of a given option and its behavior, see the |
| 91 | Tk man pages for the widget in question. |
| 92 | |
| 93 | <P> |
| 94 | Note that the man pages list "STANDARD OPTIONS" and "WIDGET SPECIFIC |
| 95 | OPTIONS" for each widget. The former is a list of options that are |
| 96 | common to many widgets, the latter are the options that are |
| 97 | ideosyncratic to that particular widget. The Standard Options are |
| 98 | documented on the <span class="manpage"><i>options</i>(3)</span> man page. |
| 99 | |
| 100 | <P> |
| 101 | No distinction between standard and widget-specific options is made in |
| 102 | this document. Some options don't apply to some kinds of widgets. |
| 103 | Whether a given widget responds to a particular option depends on the |
| 104 | class of the widget; buttons have a <code>command</code> option, labels do not. |
| 105 | |
| 106 | <P> |
| 107 | The options supported by a given widget are listed in that widget's |
| 108 | man page, or can be queried at runtime by calling the |
| 109 | <tt class="method">config()</tt> method without arguments, or by calling the |
| 110 | <tt class="method">keys()</tt> method on that widget. The return value of these |
| 111 | calls is a dictionary whose key is the name of the option as a string |
| 112 | (for example, <code>'relief'</code>) and whose values are 5-tuples. |
| 113 | |
| 114 | <P> |
| 115 | Some options, like <code>bg</code> are synonyms for common options with long |
| 116 | names (<code>bg</code> is shorthand for "background"). Passing the |
| 117 | <code>config()</code> method the name of a shorthand option will return a |
| 118 | 2-tuple, not 5-tuple. The 2-tuple passed back will contain the name of |
| 119 | the synonym and the ``real'' option (such as <code>('bg', |
| 120 | 'background')</code>). |
| 121 | |
| 122 | <P> |
| 123 | <div class="center"><table class="realtable"> |
| 124 | <thead> |
| 125 | <tr> |
| 126 | <th class="center">Index</th> |
| 127 | <th class="left" >Meaning</th> |
| 128 | <th class="left" >Example</th> |
| 129 | </tr> |
| 130 | </thead> |
| 131 | <tbody> |
| 132 | <tr><td class="center" valign="baseline">0</td> |
| 133 | <td class="left" >option name</td> |
| 134 | <td class="left" ><code>'relief'</code></td></tr> |
| 135 | <tr><td class="center" valign="baseline">1</td> |
| 136 | <td class="left" >option name for database lookup</td> |
| 137 | <td class="left" ><code>'relief'</code></td></tr> |
| 138 | <tr><td class="center" valign="baseline">2</td> |
| 139 | <td class="left" >option class for database lookup</td> |
| 140 | <td class="left" ><code>'Relief'</code></td></tr> |
| 141 | <tr><td class="center" valign="baseline">3</td> |
| 142 | <td class="left" >default value</td> |
| 143 | <td class="left" ><code>'raised'</code></td></tr> |
| 144 | <tr><td class="center" valign="baseline">4</td> |
| 145 | <td class="left" >current value</td> |
| 146 | <td class="left" ><code>'groove'</code></td></tr></tbody> |
| 147 | </table></div> |
| 148 | |
| 149 | <P> |
| 150 | Example: |
| 151 | |
| 152 | <P> |
| 153 | <div class="verbatim"><pre> |
| 154 | >>> print fred.config() |
| 155 | {'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')} |
| 156 | </pre></div> |
| 157 | |
| 158 | <P> |
| 159 | Of course, the dictionary printed will include all the options |
| 160 | available and their values. This is meant only as an example. |
| 161 | |
| 162 | <P> |
| 163 | |
| 164 | <DIV CLASS="navigation"> |
| 165 | <div class='online-navigation'> |
| 166 | <p></p><hr /> |
| 167 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 168 | <tr> |
| 169 | <td class='online-navigation'><a rel="prev" title="16.1.6 Handy Reference" |
| 170 | href="node722.html"><img src='../icons/previous.png' |
| 171 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 172 | <td class='online-navigation'><a rel="parent" title="16.1.6 Handy Reference" |
| 173 | href="node722.html"><img src='../icons/up.png' |
| 174 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 175 | <td class='online-navigation'><a rel="next" title="16.1.6.2 The Packer" |
| 176 | href="node724.html"><img src='../icons/next.png' |
| 177 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 178 | <td align="center" width="100%">Python Library Reference</td> |
| 179 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 180 | href="contents.html"><img src='../icons/contents.png' |
| 181 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 182 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 183 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 184 | <td class='online-navigation'><a rel="index" title="Index" |
| 185 | href="genindex.html"><img src='../icons/index.png' |
| 186 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 187 | </tr></table> |
| 188 | <div class='online-navigation'> |
| 189 | <b class="navlabel">Previous:</b> |
| 190 | <a class="sectref" rel="prev" href="node722.html">16.1.6 Handy Reference</A> |
| 191 | <b class="navlabel">Up:</b> |
| 192 | <a class="sectref" rel="parent" href="node722.html">16.1.6 Handy Reference</A> |
| 193 | <b class="navlabel">Next:</b> |
| 194 | <a class="sectref" rel="next" href="node724.html">16.1.6.2 The Packer</A> |
| 195 | </div> |
| 196 | </div> |
| 197 | <hr /> |
| 198 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 199 | </DIV> |
| 200 | <!--End of Navigation Panel--> |
| 201 | <ADDRESS> |
| 202 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 203 | </ADDRESS> |
| 204 | </BODY> |
| 205 | </HTML> |