Experimenting with Fonts-------------------------------------------------------------------------1 Discting a Font-----------------------------------------------------------------------------------2 Using Fonts------------------------------------------------------------------------------------------2 Geometry Management------------------------------------------------------------------------------3 The pack Geometry Manager---------------------------------------------------------------------3
Options for pack-------------------------------------------------------------------------------------------------------------------------3 The grid Geometry Manager----------------------------------------------------------------------4 grid Options-----------------------------------------------------------------------------------------------------------------------------4 Button, Checkbutton, and Radiobutton Widgets--------------------------------------------------5 Table of Options for Button-Type Widgets------------------------------------------------------6 Label and Entry Widgets-----------------------------------------------------------------------------9 The Label Widget----------------------------------------------------------------------------------10
Creating a Label-----------------------------------------------------------------------------------------------------------------------10 Label Options--------------------------------------------------------------------------------------------------------------------------10
The Entry Widget------------------------------------------------------------------------------------12 Creating the Entry Widget------------------------------------------------------------------------13 Entry Options--------------------------------------------------------------------------------------------------------------------------13 The Listbox Widget----------------------------------------------------------------------------------15 Creating and Filling a Listbox-------------------------------------------------------------------16 Listbox Options------------------------------------------------------------------------------------------------------------------------17 The Scrollbar Widget--------------------------------------------------------------------------------18 Scrollbar Options----------------------------------------------------------------------------------18 The Text, TextUndo, and ROText Widgets-------------------------------------------------------20 Text Widget Options------------------------------------------------------------------------------21
Creating a Scale------------------------------------------------------------------------------------24
Scale widget options------------------------------------------------------------------------------------------------------------------24 The Menu System-----------------------------------------------------------------------------------26 Menu Options--------------------------------------------------------------------------------------26 Menubutton Options------------------------------------------------------------------------------28 Frame, MainWindow, and Toplevel Widgets----------------------------------------------------30 Options----------------------------------------------------------------------------------------------30
Frame-Specific Options--------------------------------------------------------------------------------------------------------------32 Toplevel-Specific Options------------------------------------------------------------------------------------------------------------32
Dialog Boxes-----------------------------------------------------------------------------------------32 messageBox------------------------------------------------------------------------------------------33 Adjuster-----------------------------------------------------------------------------------------------34 LabFrame---------------------------------------------------------------------------------------------35 NoteBook---------------------------------------------------------------------------------------------35
学生的妈妈4
Fonts
Every computer system us fonts. In Perl/Tk applications, you can change any of the fonts for items inside the application, but not the fonts ud in the window decoration for titles (which are handled by the window manager). In this chapter, we'll show you how to u fonts in your Perl/Tk application.
每个计算机系统都会用到字体。你可以改变任何字体在Perl/TK应用程序中,不仅仅是用字体装饰window的标题。在这章,将讲述如何运用字体在Perl/TK应用程序中。
Experimenting with Fonts
One way to determine what font to u is to write a program using the fontFamilies method that displays various font specifications. So, before we get into the details of creating a font definition, let's look at a program that lets us play around with the fonts on our system. This program is uful no matter what operating system you're on.
用fontFamilies显示各种字体的规格,我们来确定使用什么字体是写程序。因此,在我们进入定义字体细节之前,让我们来看看一个程序,它可以让我们知道在系统中有什么字体。无论什么操作系统这个程序都可用。
Eg.
#!/usr/bin/perl -w
u Tk;
u Tk::BrowEntry;
u strict;
my $mw = MainWindow->new(-title => 'Font Viewer');
word删除水印my $f = $mw->Frame->pack(-side => 'top');
my $family = 'Courier';
my $be = $f->BrowEntry(-label => 'Family:', -variable => \$family,
-browcmd => \&apply_font)->pack(-fill => 'x', -side => 'left');
$be->inrt('end', sort $mw->fontFamilies);
my $size = 24;
my $bentry = $f->BrowEntry(-label => 'Size:', -variable => \$size,
-browcmd => \&apply_font)->pack(-side => 'left');
考研科目时间表$bentry->inrt('end', (3 .. 32));
my $weight = 'normal';
$f->Checkbutton(-onvalue => 'bold', -offvalue => 'normal',
-
text => 'Weight', -variable => \$weight,
-command => \&apply_font)->pack(-side => 'left');
my $slant = 'roman';
$f->Checkbutton(-onvalue => 'italic', -offvalue => 'roman',
-text => 'Slant', -variable => \$slant,
-command => \&apply_font)->pack(-side => 'left');
my $underline = 0;
$f->Checkbutton(-text => 'Underline', -variable => \$underline,
-command => \&apply_font)->pack(-side => 'left');
my $overstrike = 0;
$f->Checkbutton(-text => 'Overstrike', -variable => \$overstrike,
-
command => \&apply_font)->pack(-side => 'left');
my $stext = 'Sample Text';
my $sample = $mw->Entry(-textvariable => \$stext)->pack(-fill => 'x');
&apply_font;
MainLoop;
sub apply_font {
# Specify all options for font in an anonymous array
$sample->configure(-font =>
[-family => $family,
迷路的云-size => $size,
-weight => $weight,
-
slant => $slant,
-underline => $underline,
-overstrike => $overstrike]);
}
Discting a Font
This font description indicates a 24-point bold Helvetica font with Roman slant. The field order is as follows:
-foundry-family-weight-slant-sWdth-adstyl-pixelsize-pointsize-resx-resy-spacing-avgWidth-registry-encoding.
以罗马字体24域描述字型。下面具体表示24域:
若不用的域可用通配符*,如下:
font => '-*-helvetica-bold-r-*-*-*-240-*-*-*-*-*-*'
Using Fonts
Now that we know what compris a font, let's look at a few ways we can specify them in code.
现在,我们知道包括的字体,让我们用几种方法指定他们的代码。
We simplify things in our Perl/Tk applications by being able to create a single name that refers to a combination of family, size, weight, slant, underline, and overstrike:
在Perl/TK应用程序中,参考字型(字体、大小、粗体、斜体、下划线和横杠)创建简单的名字,为下文用:$code_font = $mw->fontCreate(-family => 'courier',-size => 12);
桂附丸$mw->Button(-text => "Show Code2", -font => $code_font);
Once the font is created, you can change any of its ttings using the fontConfigure method, using the font name or reference as the first argument:
一旦创建的字体,你可以用fontConfigure改变它的任何设置:蝴蝶飞呀歌词
$mw->fontConfigure($code_font, -family => 'Verdana');
在Perl/TK中显示出汉字
英伦学院风#!/usr/bin/perl -w
u Tk;
u encoding 'euc_cn';
my $mw = new MainWindow;
$code_font = $mw->fontCreate(-family => '黑体',-size => 12);
$mw->Button(-text => "欢迎", -font => $code_font)->pack;
MainLoop
Geometry Management
To display widgets on the screen, they must be pasd to a geometry manager. The geometry manager controls the position and size of the widgets in the display window. Several geometry managers are available with Perl/Tk: pack, place, grid, and form.
我们运用布局工具管理各种部件在屏幕中显示。布局工具包括位置和大小的控制。在Perl/TK有中四种变量来控制:pack、place、grid和form。
The pack Geometry Manager
To make your window look nicer and more manageable (and ur friendly), there are arguments that can be nt to the pack method that will change the way the widgets and the window look. As with anything in Perl/Tk, the arguments are arranged in key/value pairs. So the more sophisticated usage would be: $widget->pack( [ option => value, ... ] );
Options for pack
This list shows all the options available when you call pack (the default values are shown in bold):
下面列出在pcak使用时的所有选项(默认值用粗体表示)
-side => 'left' | 'right' | 'top' | 'bottom
Puts the widget against the specified side of the window or Frame
设定部件窗口或框架的位置
-fill => 'none' | 'x' | 'y'| 'both'
Caus the widget to fill the allocation rectangle in the specified direction
巴西乌龟设定部件延那个方向填充
-expand => 1 | 0
Caus the allocation rectangle to fill the remaining space available in the window or Frame
在窗口或框架中是否填补剩余的空间
-anchor => 'n' | 'ne' | 'e' | '' | 's' | 'sw' | 'w' | 'nw' | 'center'