<html><head>
<META name="keywords" content="在线手册|免费手册|手册下载|数据库|服务器|网站|资料|手册家园|软博chm家园|软件手册|软件帮助|软件查询|软件资料|数据库手册|服务器手册|网站手册|Web|php|css|asp|.net|jsp|cgi|Server|apache|iis|Database|mssql|mysql|ado|java|soft|windows|linux|freeBSD|solaris|sco|hp-ux|ibm-aix|tru64|irix|macosx|postgreSQL|oracle|informix|sybase|db2">
<script type="text/JavaScript"> if (window.name != "content") window.location = "../index.html?page=perltk%2Fch02_01.htm"; </script>
<title>Geometry Management (Mastering Perl/Tk) - 手册之家 </title><link rel="stylesheet" type="text/css" href="style/style1.css" />
<meta name="DC.Creator" content="Steve Lidie and Nancy Walsh" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="1565927168L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Mastering Perl/Tk" /><meta name="DC.Type" content="Text.Monograph" />
<script type="text/JavaScript" src="../files/supply.js"></script>
<script type="text/JavaScript">
chmtop.c2wtopf.pageid = "perltk/ch02_01.htm";
</script>
</head><body bgcolor="#ffffff">
<script type="text/javascript" src="/js/showad1.js"></script><script type="text/javascript" src="/js/showad2.js"></script>
<img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Mastering Perl/Tk" /><area shape="rect" coords="629,-11,726,25" href="perltk/jobjects/fsearch.htm" alt="Search this book" /></map>
<div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch01_06.htm"><img src="gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch02_02.htm"><img src="gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div>
<h1 class="chapter">Chapter 2. Geometry Management</h1>
<div class="htmltoc"><h4 class="tochead">Contents:</h4>
<p> <a href="ch02_01.htm#mastperltk-chp-2-sect-1">The pack Geometry Manager</a><br />
<a href="ch02_02.htm">The grid Geometry Manager</a><br />
<a href="ch02_03.htm">The place Geometry Manager</a><br />
<a href="ch02_04.htm">The form Geometry Manager</a><br />
<a href="ch02_05.htm">Geometry Management Summary</a><br /></p></div>
<p><a name="INDEX-123" /></a>To
display widgets on the screen, they must be passed to a
<em class="firstterm">geometry manager</em>. The geometry manager
controls the position and size of the widgets in the display window.
Several geometry managers are available with Perl/Tk:
<tt class="literal">pack</tt>, <tt class="literal">place</tt>,
<tt class="literal">grid</tt>, and <tt class="literal">form</tt>.
</p>
<p><a name="INDEX-124" /></a>All the geometry managers are invoked as
methods on the widget, but they all have their own methodologies and
arguments to change where and how the widgets are put on the screen:
</p>
<blockquote><pre class="code">$widget1->pack(); $widget2->place(); $widget3->grid(); $widget4->form( );</pre></blockquote>
<p><a name="INDEX-125" /></a><a name="INDEX-126" /></a>When you organize the widgets in
your window, it is often necessary to separate groups of widgets to
get a certain look and feel. For instance, when you use
<tt class="literal">pack</tt>, it is difficult to have widgets stacked both
horizontally and vertically without grouping them in some fashion. We
use a Frame widget or another window (a Toplevel widget) to group
widgets inside a window.
</p>
<p><a name="INDEX-127" /></a>We create our first window
by calling <tt class="literal">MainWindow</tt>. The MainWindow is a special
form of a Toplevel widget. For more detailed information on how to
create/configure Frame and Toplevel widgets, see <a href="ch11_01.htm">Chapter 11, "
Frame, MainWindow,and Toplevel Widgets"</a>.
</p>
<p><a name="INDEX-128" /></a>With the
exception of <tt class="literal">place</tt>, differences between the
geometry managers make it difficult (not entirely impossible, but
definitely not recommended) to use more than one geometry manager
within the same area. In
<tt class="literal">$mw</tt>, we can display many types of widgets, but if
we start using <tt class="literal">pack</tt>, we should continue to use
<tt class="literal">pack</tt> on all the widgets contained directly in
<tt class="literal">$mw</tt>. Don't switch to <tt class="literal">grid</tt>
in the middle, because the two geometry managers will get into a
<em class="emphasis">race</em> <em class="emphasis">condition</em>: one will
create its layout, which affects the geometry calculations of the
other, which affects the layout of the first, causing it to recompute
its geometries, ad infinitum. However, let's assume our
MainWindow contains a Frame, which in turn contains other widgets. We
could use <tt class="literal">pack</tt> to pack the Frame inside the
MainWindow and then we could use <tt class="literal">grid</tt> to manage
the widgets inside the Frame. See <a href="ch02_01.htm#mastperltk-chp-2-fig-1">Figure 2-1</a>.
</p>
<a name="mastperltk-CHP-2-FIG-1" /></a><div class="figure"><img src="figs/mptk.0201.gif" alt="Figure 2-1" width="257" height="181" /></div><h4 class="objtitle">Figure 2-1. Frame within a window that uses a different geometry manager</h4>
<p><a name="INDEX-129" /></a>Although the different geometry managers
have their own strengths and weaknesses, <tt class="literal">pack</tt> is
the most commonly used, so we'll discuss it first and in the
most detail. The <tt class="literal">grid</tt> geometry manager has been
improved greatly with the release of Tk 8.0 and subsequent porting to
Perl. The <tt class="literal">place</tt> geometry manager is the most
tedious to use, because you have to determine exact coordinates
(relative or absolute) for every single widget. Finally, the
<tt class="literal">form</tt> geometry manager is like a combination of
<tt class="literal">pack</tt> and <tt class="literal">place</tt>.
</p>
<div class="sect1"><a name="mastperltk-CHP-2-SECT-1" /></a>
<h2 class="sect1">2.1. The pack Geometry Manager</h2>
<p><a name="INDEX-130" /></a>Remember
when you were a child and you had those wooden puzzles to put
together? Each piece in the puzzle had exactly one place where it
could go and there weren't any overlaps allowed between pieces.
</p>
<p><a name="INDEX-131" /></a>With the <tt class="literal">pack</tt> geometry
manager, our windows are similar to the wooden puzzle, because
widgets cannot overlap or cover each other, partially or completely
(see <a href="ch02_01.htm#mastperltk-chp-2-fig-2">Figure 2-2</a>). If a Button is packed in a
certain space on the window, the next Button (or any widget) will
have to fit around the already packed Button. Luckily, our windows
will be dealing only with rectangular shapes instead of funny-shaped
puzzle pieces.
</p>
<a name="mastperltk-CHP-2-FIG-2" /></a><div class="figure"><img src="figs/mptk.0202.gif" alt="Figure 2-2" width="377" height="181" /></div><h4 class="objtitle">Figure 2-2. Overlap error</h4>
<p>The order in which you pack your widgets is very important because it
directly affects what you see on the screen. Each Frame or Toplevel
maintains a list of items that are displayed within it. This list has
an order to it: if widget A is packed before widget B, then widget A
will get preference if space becomes scarce. This will become clear
as we go through some examples. You will often get a different look
to your window just by packing the widgets in a different order.
</p>
<p>If you don't care what the window looks like and how the
widgets are put in it, you can use <tt class="literal">pack
没有合适的资源?快使用搜索试试~ 我知道了~
Perl.TK (TK for perl)
共591个文件
htm:309个
gif:281个
css:1个
4星 · 超过85%的资源 需积分: 50 151 下载量 126 浏览量
2008-11-11
21:37:16
上传
评论
收藏 2.52MB 7Z 举报
温馨提示
Perl.TK Perl.TK Perl.TK
资源推荐
资源详情
资源评论
收起资源包目录
Perl.TK (TK for perl) (591个子文件)
style1.css 564B
mptk.1502.gif 85KB
mptk.2308.gif 77KB
mptk.0104.gif 60KB
mptk.0103.gif 50KB
mptk.1504.gif 47KB
mptk.2204.gif 46KB
mptk.1710.gif 39KB
mptk.1510.gif 32KB
mptk.1721.gif 32KB
mptk.1506.gif 31KB
mptk.2311.gif 31KB
mptk.2203.gif 30KB
mptk.1714.gif 29KB
mptk.0303.gif 29KB
mptk.1507.gif 28KB
mptk.2309.gif 28KB
mptk.2313.gif 27KB
mptk.1903.gif 27KB
mptk.2205.gif 26KB
mptk.1720.gif 26KB
mptk.1511.gif 26KB
mptk.1213.gif 25KB
mptk.2002.gif 24KB
mptk.1204.gif 22KB
mptk.2004.gif 22KB
mptk.0227.gif 21KB
mptk.0253.gif 21KB
mptk.2302.gif 21KB
mptk.2310.gif 19KB
mptk.1802.gif 19KB
mptk.1501.gif 19KB
mptk.0228.gif 18KB
mptk.1719.gif 18KB
mptk.1712.gif 17KB
mptk.2003.gif 17KB
mptk.1104.gif 17KB
mptk.1711.gif 16KB
mptk.1722.gif 16KB
mptk.1809.gif 16KB
mptk.0205.gif 16KB
mptk.1602.gif 16KB
mptk.1101.gif 15KB
mptk.0248.gif 15KB
mptk.0807.gif 15KB
mptk.0407.gif 15KB
mptk.1902.gif 14KB
mptk.2206.gif 14KB
mptk.1201.gif 13KB
mptk.1806.gif 13KB
banner.gif 12KB
mptk.0302.gif 12KB
mptk.1801.gif 12KB
mptk.0304.gif 12KB
mptk.1804.gif 12KB
mptk.2102.gif 12KB
mptk.1701.gif 11KB
mptk.0301.gif 11KB
mptk.2202.gif 11KB
mptk.0305.gif 11KB
mptk.1405.gif 11KB
mptk.1207.gif 11KB
mptk.1601.gif 11KB
mptk.2307.gif 11KB
mptk.0506.gif 10KB
mptk.1105.gif 10KB
mptk.2312.gif 10KB
mptk.1411.gif 10KB
mptk.2316.gif 10KB
mptk.0405.gif 10KB
mptk.1404.gif 10KB
mptk.1406.gif 9KB
mptk.1202.gif 9KB
mptk.2314.gif 9KB
mptk.0703.gif 9KB
mptk.0908.gif 9KB
mptk.2305.gif 9KB
mptk.1412.gif 9KB
mptk.ac03.gif 9KB
mptk.1702.gif 8KB
mptk.1505.gif 8KB
mptk.0252.gif 8KB
mptk.2304.gif 8KB
mptk.1901.gif 8KB
mptk.2318.gif 8KB
mptk.0615.gif 8KB
mptk.1803.gif 8KB
mptk.1401.gif 8KB
mptk.1808.gif 8KB
mptk.1403.gif 8KB
mptk.0604.gif 8KB
mptk.0404.gif 8KB
mptk.1708.gif 8KB
mptk.ac01.gif 7KB
mptk.1103.gif 7KB
mptk.2306.gif 7KB
mptk.1206.gif 7KB
mptk.0249.gif 7KB
mptk.0250.gif 7KB
mptk.0803.gif 7KB
共 591 条
- 1
- 2
- 3
- 4
- 5
- 6
dewpark
- 粉丝: 6
- 资源: 84
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页