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.)


In reply to Re: Understanding Tk::FontDialog? by keszler
in thread Understanding Tk::FontDialog? by Elijah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.