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

📄 213.html

📁 Python Ebook Python&XML
💻 HTML
📖 第 1 页 / 共 2 页
字号:

				</pre>

				<P>As you could see, we used the Label widget to implement the <TT Class="monofont">statusbar</tt> in order to be able to change the text value later. Pretty nice, isn't it?<a name="idx1073749351"></a>
					<a name="idx1073749352"></a>
					<a nAme="idx1073749353"></A>
					<a naMe="idx1073749354"></a>
					<a nAme="idx1073749355"></a>
					<A NAMe="idx1073749356"></a>
					<a nAME="idx1073749357"></A>
					<a namE="idx1073749358"></A>
				</P>

				<P>Now, have a look at the final shape of our interface (<a hreF="213#1.html">Figure 15.16</A>).</P>

				<Center>
					<h5>
<a name="1"></a>Figure 15.16. This figure shows the complete example of designing the structure of an application using Tkinter.</h5>
					
						
							<img bordEr="0" wIdth="120" HeighT="80" src="graphics/15fig16.gif" ALT="graphics/15fig16.gif">
						
					
				</CenteR>

				<P>In my opinion, one of the greatest things about designing GUI applications using Tkinter is the number of things that are already done and ready to be used by your applications. Some examples are the following modules, which are part of the Tkinter distribution, and implement common dialog boxes.</P>

				<BlockQUOTe>
<p>
						<a nAME="idx1073749359"></A>
						<a name="idx1073749360"></a>
						<p><tt class="monofont">tkMessageBox</tt>棤
    This module implements the classic Yes/No and Abort/Retry/Ignore dialog styles.</p>

					</p>
<p>
						<a NamE="idx1073749361"></a>
						<a nAme="idx1073749362"></a>
						<p><Tt clASS="monofont">tkSimpleDialog</Tt>棤
    This module implements a base class that can be used to implement other modules.</p>

					</p>
<p>
						<A NAMe="idx1073749363"></a>
						<a nAME="idx1073749364"></A>
						<p><tt cLASS="monofont">tkFileDialog</tt>棤
    This module implements a file dialog, which is very close to the file dialogs found in the Windows system.</p>

					</p>
<p>
						<a name="idx1073749365"></a>
						<a name="idx1073749366"></a>
						<p><tt ClaSs="monofont">tkColorChooser</tt>棤
    This module implements a dialog that allows you to choose and pick a color.</P>

					</p>
</bloCkquOTE>
				<P>The usage of these modules is very simple. The next example opens a <a namE="idx1073749367"></A>
					<A Name="idx1073749368"></a>
					<A NAMe="idx1073749369"></a>
					<a nAME="idx1073749370"></A>file dialog box, which allows you to browse the files through your local directory, and returns the filename selected (see <a href="213#2.html">Figure 15.17</a>).</p>

				<center>
					<h5>
<a name="2"></a>Figure 15.17. Note that the FileDialog returns the name of the selected file, and our application shows that name on the status bar.</H5>
					
						
							<imG borDer="0" wiDth="323" hEIGHt="266" src="graphics/15fig17.gif" ALT="graphics/15fig17.gif">
						
					
				</CenteR>

				<PRE>
					
from Tkinter import *
import tkFileDialog
def openwindows():
    statusbar.config(text = open.show())


root = Tk()
myfiletypes = [('Python files', '*.py'), ('All files', '*')]
open = tkFileDialog.Open(root, filetypes = myfiletypes)
Button(root, text="Open File Dialog", command=openwindows).pack()

statusbar = Label(root, text="", bd=1, relief=SUNKEN, anchor=W)
statusbar.pack(side=BOTTOM, fill=X)
root.mainloop()

				</pre>

				<p>As you could notice, this is a very simple example of the power of Tkinter, but the concept of creating a dialog is as simple as the concept of creating a window.<A NAMe="idx1073749371"></a>
					<a name="idx1073749372"></a>
					<a name="idx1073749373"></a>
					<a name="idx1073749374"></a>
					<A naMe="idx1073749375"></a>
					<a Name="idx1073749376"></a>
					<A namE="idx1073749377"></A>
					<A Name="idx1073749378"></a>
				</P>

				<P>After creating a Toplevel widget and making the call to open the dialog, the standard dialog only returns to the Toplevel widget when it is closed. When you start facing problems like this, you have several solution options, such as opening several dialogs and making them run in parallel. Or you can create the dialog and only return the control back to the Toplevel widget when the dialogs are closed by the user, creating a modal behavior. This solution is implemented using the <TT clasS="monofont">wait_window</TT> method, which creates a local event loop, and only returns when the window informed as an argument is closed.</P>

				<p>Although application modal dialogs are easier to program, most users find them much more annoying. If possible, only use modal dialogs where some action has to be performed before the application can continue.</p>

				<p>That's it. Our overview about Tkinter ends here. Next you will see a toolkit that extends the set of available widgets you can use, and next you will find a list of useful resources for a more advanced approach on this topic.<a NAME="idx1073749379"></a>
					<a name="idx1073749380"></a>
					<a name="idx1073749381"></a>
					<a name="idx1073749382"></a>
					<a NamE="idx1073749383"></a>
					<a nAme="idx1073749384"></a>
					<a Name="idx1073749385"></A>
					<A NAme="idx1073749386"></a>
				</p>

			</FONT>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, &copy;&nbsp;2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="212.html" title="Tkinter Widgets"><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=213" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="213.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="214.html" title="PMW桺ython Mega Widgets"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
applications<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;designing<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749345">Tkinter module</a> <a href="#idx1073749356">2nd</a> <a href="#idx1073749376">3rd</a> <a href="#idx1073749384">4th</a><BR>
creating<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749367">file dialog boxes</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749334">menus</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749348">status bars</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749337">toolbars</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749330">windows</a><BR>
designing<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applications<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749344">Tkinter module</a> <a href="#idx1073749355">2nd</a> <a href="#idx1073749375">3rd</a> <a href="#idx1073749383">4th</a><BR>
dialog boxes<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749370">creating</a><BR>
file dialog boxes<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749368">creating</a><BR>
graphical user interfaces (GUIs)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tkinter<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749341">designing applications</a> <a href="#idx1073749352">2nd</a> <a href="#idx1073749372">3rd</a> <a href="#idx1073749380">4th</a><BR>
interfaces<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graphical user (GUI)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749342">Tkinter</a> <a href="#idx1073749353">2nd</a> <a href="#idx1073749373">3rd</a> <a href="#idx1073749381">4th</a><BR>
menus<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749335">creating</a><BR>
modules<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749366">tkColorChooser</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749364">tkFileDialog</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tkinter<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749343">designing applications</a> <a href="#idx1073749354">2nd</a> <a href="#idx1073749374">3rd</a> <a href="#idx1073749382">4th</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749360">tkMessageBox</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749362">tkSimpleDialog</a><BR>
programs<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;designing<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749346">Tkinter module</a> <a href="#idx1073749357">2nd</a> <a href="#idx1073749377">3rd</a> <a href="#idx1073749385">4th</a><BR>
root windows<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749331">creating</a><BR>
software<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;designing<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749347">Tkinter module</a> <a href="#idx1073749358">2nd</a> <a href="#idx1073749378">3rd</a> <a href="#idx1073749386">4th</a><BR>
status bars<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749349">creating</a><BR>
 <a href="#idx1073749365">tkColorChooser module</a><BR>
 <a href="#idx1073749363">tkFileDialog module</a><BR>
Tkinter module<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749340">designing applications</a> <a href="#idx1073749351">2nd</a> <a href="#idx1073749371">3rd</a> <a href="#idx1073749379">4th</a><BR>
 <a href="#idx1073749359">tkMessageBox module</a><BR>
 <a href="#idx1073749361">tkSimpleDialog module</a><BR>
toolbars<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749338">creating</a><BR>
windows<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749332">creating</a><BR>
writing<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749369">file dialog boxes</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749336">menus</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749350">status bars</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749339">toolbars</a><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#idx1073749333">windows</a><BR>
<BR>
</font></TD></TR></TABLE>




<!--EndOfBrowse-->

</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>

⌨️ 快捷键说明

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