Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (6.44 MB, 72 trang )
[Chapter 18] 18.2 Geometry Managers
Causes the allocation rectangle to fill the remaining space available in the window. Values are 'yes',
'no', 1, and 0. The default is 0 ('no').
-anchor => position
Anchors the widget inside the allocation rectangle. Values for position are 'n', 'ne', 'e',
'se', 's', 'sw', 'w', 'nw', and 'center'. The default is 'center'.
-after => $widget
Puts the widget after another widget in packing order.
-before => $widget
Puts the widget before another widget in packing order.
-in => $window
Packs the widget inside another window rather than inside its parent.
-ipadx => amount
Increases the size of the widget horizontally by amount * 2. amount can be represented as a number
followed by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default
units.
-ipady => amount
Increases the size of the widget vertically by amount * 2. amount can be represented as a number
followed by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default
units.
-padx => amount
Places padding on the left and right of the widget. amount can be represented as a number followed
by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default units.
-pady amount
Places padding on the top and bottom of the widget. amount can be represented as a number followed
by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default units.
18.2.1.1 Pack methods
The following methods are associated with pack:
packForget
Causes a widget to be removed from view.
$widget->packForget;
The widget is not destroyed, but is no longer managed by pack. The widget is removed from the
packing order, so if it were repacked later, it would appear at the end of the packing order.
packInfo
Returns a list containing all pack information about that widget.
$info = $widget->packInfo;
packPropagate
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_02.htm (2 of 6) [2/7/2001 10:37:22 PM]
[Chapter 18] 18.2 Geometry Managers
Suppresses automatic resizing of a Toplevel or Frame widget to accommodate items packed inside of
it. The following line turns off automatic resizing:
$widget->packPropagate(0);
packSlaves
Returns an ordered list of all the widgets packed into the parent widget.
$children = $widget->packSlaves;
18.2.2 The grid Geometry Manager
The grid geometry manager divides the window into a grid composed of columns and rows starting at 0,0
in the upper left-hand corner. The resulting grid resembles a spreadsheet, with each widget assigned a cell
according to the options to grid. To create a grid, create a frame that is packed inside the parent window
and then grid the widgets within the frame.
You can specify explicit rows and columns using options to grid. However, if several widgets are meant to
appear in the same row, you can use a single grid command with a list of widgets rather than calling grid
for each one. The first widget invokes the grid command, and all other widgets for that column are
specified as options to grid. Any subsequent grid commands increment the row by one and start again.
You can use special characters as placeholders:
- (minus sign)
The previous widget should span this column as well. May not follow ^ or x.
x
Leave a blank space.
^
The widget above this one (same column, previous row) should span this row.
Options to grid are:
-column => n
The column in which to place the widget. n is any integer >= 0.
-row => m
The row in which to place the widget. m is any integer >= 0.
-columnspan => n
The number of columns for the widget to span, beginning with the column specified with -column. n
is any integer > 0.
-rowspan => m
The number of rows for the widget to span, beginning with the column specified with -row. m is any
integer > 0.
-sticky => sides
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_02.htm (3 of 6) [2/7/2001 10:37:22 PM]
[Chapter 18] 18.2 Geometry Managers
Stick widget to specified side(s). sides contains characters n, s, e, or w.
-in => $window
Grid widget inside another window instead of its parent.
-ipadx => amount
Increases the size of the widget horizontally by amount * 2. amount can be represented as a number
followed by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default
units.
-ipady => amount
Increases the size of the widget vertically by amount * 2. amount can be represented as a number
followed by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default
units.
-padx => amount
Places padding on the left and right of the widget. amount can be represented as a number followed
by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default units.
-pady amount
Places padding on the top and bottom of the widget. amount can be represented as a number followed
by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default units.
18.2.2.1 Grid methods
The following methods are associated with grid:
gridColumnconfigure
Configures the column specified by the first argument using -weight and -minsize arguments.
The -weight argument determines the amount of space to allocate to that column, and the
-minsize argument sets the minimum size in pixels. For example:
$widget->gridColumnconfigure(3, -weight => 1);
gridRowconfigure
Configures the row specified by the first argument using -weight and -minsize arguments. The
-weight argument determines the amount of space to allocate to that row, and the -minsize
argument sets the minimum size in pixels. For example:
$widget->gridRowconfigure(3, -weight => 1);
gridBbox
Returns the bounding box in pixels for the space occupied by the specified grid position (in the order
of column, row). For example:
$widget->gridBbox(3,2);
gridForget
Causes the widget(s) to be removed from view. Additional widgets can be specified as arguments.
$widget1->gridForget($widget2, widget3, ...);
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_02.htm (4 of 6) [2/7/2001 10:37:22 PM]
[Chapter 18] 18.2 Geometry Managers
gridInfo
Returns information about the widget in list format.
$widget->gridInfo;
gridLocation
Returns the column and row of the widget nearest the specified x,y coordinates (in pixels).
$widget->gridLocation(120, 32);
gridPropagate
Turns off automatic resizing of the widget.
$widget->gridPropagate;
gridSize
Returns the size of the grid, i.e., the number of columns and rows.
$widget->gridSize;
gridSlaves
Returns a list of all widgets contained within a master widget. Optional -row and -column
arguments restrict the response to the widget(s) within that row or column.
$children = $widget->gridSlaves(-row => 2);
18.2.3 The Place Geometry Manager
The place geometry manager lets you position a window at explicit x,y coordinates. With place, you can
overlap widgets, which isn't allowed with grid or pack. For example, to position a button widget at the
upper left corner of a window:
$button->place(-x => 0, -y => 0);
Options to place are:
-anchor => position
The position in the widget that will be placed at the coordinates specified. Values for position are
'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', and 'center'. Default is 'nw'.
-bordermode => location
Determines whether or not the border portion of the widget is included in the coordinate system.
Values for location are 'inside', 'outside', and 'ignore'.
-height => amount
Absolute height of the widget. amount can be represented as a number followed by c (centimeters), i
(inches), m (millimeters), and p (printer points). Pixels are the default units.
-in => $window
The child widget will be packed inside the specified window instead of the parent that created it. Any
relative coordinates or sizes will still refer to the parent.
-relheight => ratio
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_02.htm (5 of 6) [2/7/2001 10:37:22 PM]
[Chapter 18] 18.2 Geometry Managers
The height of the widget relates to the parent widget's height by the specified ratio.
-relwidth => ratio
The width of the widget relates to the parent widget's width by the specified ratio.
-relx => xratio
The widget will be placed relative to its parent by the specified ratio. xratio is a floating point
number from 0.0 to 1.0, with 0.0 representing the left side of the parent widget and 1.0 representing the
right side.
-rely => yratio
The widget will be placed relative to its parent by the specified ratio. yratio is a floating point
number from 0.0 to 1.0, with 0.0 representing the top of the parent widget and 1.0 representing the
bottom.
-width => amount
The width of the widget will be the specified amount. amount can be represented as a number
followed by c (centimeters), i (inches), m (millimeters), and p (printer points). Pixels are the default
units.
-x => xcoord
The widget will be placed at the specified x coordinate.
-y => ycoord
The widget will be placed at the specified y coordinate.
The following methods are associated with place:
placeForget
Causes the widget to be removed from view.
placeInfo
Returns information about the widget.
placeSlaves
Returns a list of widgets managed by the specified parent widget.
18.1 Widgets
18.3 Common Widget
Configuration Options
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming
| Perl Cookbook ]
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_02.htm (6 of 6) [2/7/2001 10:37:22 PM]
[Chapter 18] 18.3 Common Widget Configuration Options
Chapter 18
Perl/Tk
18.3 Common Widget Configuration Options
In the remainder of this chapter, we'll be discussing each widget: the command used to create each
widget, the options used to configure them, and the methods for manipulating them.
You'll find that there are many, many configuration options that are shared by multiple widgets. We
could list them individually for each widget, but in the interest of saving a tree or two, we're instead
going to list the shared options up front, rather than repeating them over and over. That way we can
concentrate on the options that are crucial to the behavior of each particular widget, and save the reader
from being lost in a sea of options.
The following options are supported by the widgets noted:
-activebackground => color
Sets the background color when the mouse cursor is over the widget.
Applicable widgets: Button, Checkbutton, Menu, Menubutton, Optionmenu, Radiobutton, Scale,
Scrollbar
-activeforeground => color
Sets the text color when the mouse cursor is over the widget. Applicable widgets: Button,
Checkbutton, Menu, Menubutton, Optionmenu, Radiobutton
-anchor => position
Causes the text to stick to that position in the widget. Values for position are 'n', 'ne', 'e',
'se', 's', 'sw', 'w', 'nw', and 'center'. Applicable widgets: Button, Checkbutton,
Label, Menubutton, Optionmenu, Radiobutton
-background => color
-bg => color
Sets the background of the widget to the specified color. Applicable widgets: Button, Canvas,
Checkbutton, Entry, Frame, Label, Listbox, Menu, Menubutton, Optionmenu, Radiobutton, Scale,
Scrollbar, Text, Toplevel
-bitmap => 'bitmapname'
Uses a bitmap instead of text in the widget. You can specify either a default bitmap or the location
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_03.htm (1 of 5) [2/7/2001 10:37:26 PM]
[Chapter 18] 18.3 Common Widget Configuration Options
of a bitmap file (with @ in front of the path). Applicable widgets: Button, Checkbutton, Label,
Menubutton, Optionmenu, Radiobutton
-borderwidth => amount
-bd => amount
Changes the width of the edge drawn around the widget. Applicable widgets: Button, Canvas,
Checkbutton, Entry, Frame, Label, Listbox, Menu, Menubutton, Optionmenu, Radiobutton, Scale,
Scrollbar, Text, Toplevel
-cursor => 'cursorname'
Mouse cursor will change to specified cursor when over the widget. Applicable widgets: Button,
Canvas, Checkbutton, Entry, Frame, Label, Listbox, Menu, Menubutton, Optionmenu,
Radiobutton, Scale, Scrollbar, Text, Toplevel
-disabledforeground => color
Sets the color of the text when the widget is disabled. Applicable widgets: Button, Checkbutton,
Menu, Menubutton, Optionmenu, Radiobutton
-exportselection => boolean
Determines whether selected text is exported to the window system's clipboard. (For a listbox,
-exportselection => 1 means two listboxes cannot have selections at the same time.)
Applicable widgets: Entry, Listbox, Text
-font => 'fontname'
Changes the font of all the text on the widget to fontname. Applicable widgets: Button,
Checkbutton, Entry, Label, Listbox, Menu, Menubutton, Optionmenu, Radiobutton, Scale, Text
-foreground => color
-fg => color
Changes the text color to color. Applicable widgets: Button, Checkbutton, Entry, Label, Listbox,
Menu, Menubutton, Optionmenu, Radiobutton, Scale, Text
-height => amount
Specifies the height of the widget. amount represents a number of characters if text is displayed,
or a screen distance if an image or bitmap is displayed. Applicable widgets: Button, Canvas,
Checkbutton, Frame, Label, Listbox, Menubutton, Optionmenu, Radiobutton, Text, Toplevel
-highlightbackground => color
Sets the color of a non-focus rectangle. Applicable widgets: Button, Canvas, Checkbutton, Entry,
Frame, Label, Listbox, Menubutton, Optionmenu, Radiobutton, Scale, Scrollbar, Text, Toplevel
-highlightcolor => color
Sets the color of the focus rectangle. Applicable widgets: Button, Canvas, Checkbutton, Entry,
Frame, Label, Listbox, Menubutton, Optionmenu, Radiobutton, Scale, Scrollbar, Text, Toplevel
-highlightthickness => amount
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_03.htm (2 of 5) [2/7/2001 10:37:26 PM]