in reply to Understanding Tk::FontDialog?
A better method would be to use fontCreate and fontConfigure. This example should point you in the right direction:
#!/usr/bin/perl # vi: set ts=8 sw=2 et: use warnings; use strict; use Tk; use Data::Dump qw(dump); my $list; my $parent; my $mw = MainWindow->new(); $mw->title("Listbox"); $mw->geometry("300x300+100+100"); $mw->fontCreate( 'lbl', -family => 'arial', -size => '10', -weight + => 'normal' ); $mw->fontCreate( 'lblbtn', -family => 'arial', -size => '14', -weight + => 'bold' ); my $l1 = $mw->Label( -font => 'lbl', -text => "dsal kjhdsa")->pack( -s +ide => 'top', -fill => 'y', -expand => 1 ); my $l2 = $mw->Label( -font => 'lbl', -text => "lkah dsl kj")->pack( -s +ide => 'top', -fill => 'y', -expand => 1 ); my $l3 = $mw->Label( -font => 'lbl', -text => "ih kah klzv")->pack( -s +ide => 'top', -fill => 'y', -expand => 1 ); my $l4 = $mw->Label( -font => 'lbl', -text => "lajd smbl j")->pack( -s +ide => 'top', -fill => 'y', -expand => 1 ); my $l5 = $mw->Label( -font => 'lbl', -text => "lk javh lkj")->pack( -s +ide => 'top', -fill => 'y', -expand => 1 ); $mw->Button( -text => "Change Label-3 Font", -font => 'lblbtn', -command => [ \&chg_font, "widget", $l3 ], )->pack( -side => 'top', -fill => 'none' ); $mw->Button( -text => "Change Label Font", -font => 'lblbtn', -command => [ \&chg_font, "font", "lbl" ], )->pack( -side => 'top', -fill => 'none' ); $mw->Button( -text => "Change Button Font", -font => 'lblbtn', -command => [ \&chg_font, "font", "lblbtn" ], )->pack( -side => 'top', -fill => 'none' ); MainLoop; sub chg_font { my $type = shift; my $which = shift; my $newfont = $mw->FontDialog->Show; if ($type eq "widget") { $which->configure(-font => $newfont); } else { $mw->fontConfigure($which, $mw->fontActual($newfont)); } }
(Note that once you use the "Change Label-3" button, label 3 will no longer be affected by the "Change Label Font" button.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Understanding Tk::FontDialog?
by Elijah (Hermit) on Aug 24, 2004 at 02:38 UTC | |
by keszler (Priest) on Aug 24, 2004 at 05:25 UTC |