[ Pobierz całość w formacie PDF ]
.The slant can be "i" for italic or "r" for regular.To set the font of a widget, youconfigure its font property: $label->configure (font => '-adobe-helvetica-medium-r-normal--8-80-75-75-p-46-*-1');Once Perl/Tk is ported to the Windows and Mac, font values can be specified in either the XLFD format or thesimpler Windows style: Helvetica 24 bold.The former format will continue to be supported on all platforms.14.3.1.2 ImagesSome widgets, such as buttons and labels, can display two-color bitmaps or multi-color pixmaps.Because thesame bitmap or image can be used to decorate more than one widget, Tk considers them to be objects that arerendered in one or more places.That is, the image object holds the data, and the widgets know how to renderthem in their own space.Hence, two steps are involved in displaying a bitmap or a pixmap on a widget: createan image object given an image file, and configure the widget's bitmap or pixmap property with the imageobject.Depending on the type of image file you have, you have to make one of three calls to create the appropriate typeof image object:#For XBM (X Bitmaps) only$image = $label->Bitmap(file => 'face.xbm');#For XPM (X Pixmaps only)$image = $label->Pixmap(file => 'smiley.xpm');#For GIF or PPM (Portable pixmap) formats, use the Photo constructor$image = $label->Photo(file => 'frown.gif');Now you can change the label's image easily:$label->configure (image => $image);Note that if the image is a bitmap, you must use the "bitmap" option, and if it is an XPM or GIF files, use the"image" property.In the bitmap case, the "foreground" and "background" options dictate the two colors; forimages, the file supplies its own colors.14.3.1.3 ColorsColors can be given symbolic names such as "red" and "yellow." The library directory in an X installation has afile called rgb.txt that enumerates all the available symbolic names.Alternatively, you can give RGB values inthe form #RGB, #RRGGBB, #RRRGGGBBB, or #RRRRGGGGBBBB, where each R, G, or B represents onehexadecimal digit of red, green, or blue intensity, respectively.Our detour is now complete; let us briefly visit Tk's and Tix's widgets.14.3.2 Labels and ButtonsThe standard widget properties described in Table A.1 pretty much cover everything that labels have to offer.They are also fairly self-explanatory, so we will not say more about them.Buttons are labels with one additional property - the "command" option, which allows you to associate acallback with a button click.The next example shows the callback procedure, change_label, toggling the labelof the widget: use Tk;$top = MainWindow->new();$button = $top->Button(text => 'Start',command => \&change_label);$button->pack();MainLoop();sub change_label { # Create$button->cget('text') eq "Start" ?$button->configure(text => 'Stop') :$button->configure(text => 'Start');}The cget method retrieves the value of a configurable property.The callback can instead be a closure, like this (omitting the rest of the boiler-plate code):$button = $top->Button(text => 'Start',command => sub {$button->cget('text') eq "Start" ?$button->configure(text => 'Stop') :$button->configure(text => 'Start')}}A third way of configuring the command property is to give it an anonymous array whose first element is thecallback procedure parameter.The other elements of this array are passed to the callback when it is invoked:$button->configure (command => [\&change_label, "new label"]);We'll use this style in application-defined scrolling later in this chapter.14.3.3 Radiobuttons and CheckbuttonsA radiobutton is a widget that displays a textual string, bitmap, or image and a diamond called an indicator (seeFigure 14.3).Radiobuttons, like buttons, support the "command" option.Unlike buttons, however, radiobuttonsare typically used in groups to give the user an option to select one of many choices.For this reason, aradiobutton provides two properties called variable and value for synchronizing with the others in its group sothat only one indicator is "on." If you click on a radiobutton, that enables its indicator and changes its associatedvariable's value to its own value property.Conversely, if that variable's value is changed, the radiobutton checksto see whether it matches its own value property; if so, it turns its own indicator on.As you may have guessed,the tie facility is used internally to monitor changes to the variable.Figure 14.3: Radiobutton exampleThe following example builds a radiobutton group.$bev is the synchronizing variable [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • necian.htw.pl