Binding variable to check box : Checkbox « GUI « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » GUI » Checkbox 
Binding variable to check box
 

#!/usr/local/bin/perl -w
use Tk;
use strict;

require Tk::BrowseEntry;

my $mw = MainWindow->new(-title => 'Font Viewer');

my $f = $mw->Frame->pack(-side => 'top');

my $family = 'Courier';

my $be = $f->BrowseEntry(
    -label     => "Family:"
    -variable  => \$family, 
    -browsecmd => \&apply_font,
)->pack(-fill => 'x', -side => 'left');
$be->insert('end', sort $mw->fontFamilies);

my $size = 24;

my $bentry = $f->BrowseEntry(
    -label     => 'Size',
    -variable  => \$size, 
    -browsecmd => \&apply_font,
)->pack(-side => 'left');
$bentry->insert('end', (.. 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 = "www.java2s.com";
my $sample = $mw->Entry(-textvariable => \$stext)->pack(-fill => 'x');

&apply_font;

MainLoop;

sub apply_font {
    $sample->configure(-font => 
           [-family => $family,
      -size => $size,
      -weight => $weight,
      -slant => $slant,
      -underline => $underline,
      -overstrike => $overstrike
           ],
    );
}

   
  
Related examples in the same category
1.Create CheckBox button
2.Adding Check Box Button to Frame
3.Check 'Check Box Button' Selection Value
4.Each check button has its own variable
5.Build a list of Check Box by using the value in an array
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.