in reply to Understanding Tk::FontDialog?

The selected font is returned, into $font_set in your example. You then need to reconfigure your widgets to use the font, i.e. $widget->configure( -font => $font_set

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
    Yeah that works great if I want to change the font values every time I launch the application but I need a way to store the changed values in plain text (non-hex) such as "Courier New" and font size "10" or something.

    www.perlskripts.com
      Take a look at what $mw->fontActual($newfont) returns:

      "-family", "MS Sans Serif", "-size", -11, "-weight", "normal", "-slant", "roman", "-underline", 0, "-overstrike", 0

      You can easily write that to a file, read it back, and use it in the arguments to fontCreate or fontConfigure.