use Tk; use strict; my (%char_num, $jc, %wg, %wg_res, $jrow, $jcol, $cou); require Tk::BrowseEntry; my $mw = MainWindow->new(-title => 'Font Viewer'); my $f = $mw->Frame->grid(-row => 0, -column => 0); my $family = 'Courier'; $jcol = 0; my $be = $f->BrowseEntry( -label => "Family:", -variable => \$family, -browsecmd => \&apply_font, )->grid(-row => 0, -column => $jcol); $be->insert('end', sort $mw->fontFamilies); $jcol += 1; my $size = 14; my $bentry = $f->BrowseEntry( -label => 'Size', -variable => \$size, -browsecmd => \&apply_font, )->grid(-row => 0, -column => $jcol); $bentry->insert('end', (3 .. 32)); $jcol += 1; my @weight_options = qw (normal bold medium book light demi demibold); my $weight = "normal"; $f->Optionmenu( -variable => \$weight, -options => [@weight_options], -command => \&apply_font, )->grid(-row => 0, -column => $jcol); $jcol += 1; my $slant = "roman"; $f->Checkbutton( -onvalue => "italic", -offvalue => "roman", -text => "Slant", -variable => \$slant, -command => \&apply_font, )->grid(-row => 0, -column => $jcol); $jcol += 1; my $underline = 0; $f->Checkbutton( -text => "Underline", -variable => \$underline, -command => \&apply_font, )->grid(-row => 0, -column => $jcol); $jcol += 1; my $overstrike = 0; $f->Checkbutton( -text => "Overstrike", -variable => \$overstrike, -command => \&apply_font, )->grid(-row => 0, -column => $jcol); #my $stext = "Sample Text"; # set up all characters my $stext = ''; for($jc = 1; $jc <= 255; $jc ++) { $stext .= chr($jc); } # add the lables and entries $jcol = -1; $jrow = 0; my $f2 = $mw->Frame->grid(-row => 1, -column => 0); for($cou = 1; $cou <= 255; $cou ++) { $jcol += 1; if($jcol >= 25) { $jcol = 0; $jrow += 2; } $f2->Label(-text => $cou, -justify => 'center')->grid(-row => $jrow, -column => $jcol); $wg_res{$cou} = chr($cou); $wg{$cou}= $f2->Label(-text => $wg_res{$cou}, -justify => 'center', -bg => 'white')->grid(-row => $jrow+1, -column => $jcol, -padx => 1); # $wg{$cou} = $f2->Entry(-textvariable => \$wg_res{$cou}, -width =>3, -justify => 'center')->grid(-row => $jrow + 1, -column => $jcol); } my $sample; &apply_font; MainLoop; sub apply_font { my $jwg; foreach $jwg (sort {$a <=> $b} keys %wg) { $wg{$jwg}->configure(-font => [-family => $family, -size => $size, -weight => $weight, -slant => $slant, -underline => $underline, -overstrike => $overstrike ], ); } }