Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

It seems that despite what the docs say, you have to use the descriptive name to set the font.

Anyhow a better way than destroying and recreating the HList widget, is to clear the contents and than add new contents like in the following example:

use strict; use warnings; use Tk; use Tk::HList; use Tk::ItemStyle; use Tk::FontDialog; my $mw = MainWindow->new; $mw->title("View"); $mw->minsize(560, 180); my $font = '{Architects Daughter} -12 bold'; # have to use descriptive + name my $top = $mw->Frame()->pack( -side => 'top', -fill => 'both', -expand => +0 ); my $hlistframe = $mw->Frame()->pack( -side => 'top', -fill => 'both', -expand => +1 ); my $bottomframe = $mw->Frame()->pack( -fill => 'x', -expand => 0 ); my $menubutton = $top->Menubutton( -text => "Font", )->pack( -side => 'left' ); $menubutton->command( -label => "Change", -command => sub { $font = $mw->FontDialog->Show; $mw->RefontTree( -font => $font ) if defined $font; print "Font changed: $font\n"; } ); my $hl = $hlistframe->Scrolled( 'HList', -scrollbars => 'ose', -columns => 2, -header => 1, -height => -1, )->pack( -fill => 'both', -expand => 1 ); my $label1 = $hl->Label( -text => "Tool", -anchor => 'w' ); $hl->headerCreate( 0, -itemtype => 'window', -widget => $label1 ); my $label2 = $hl->Label( -text => "Vendor", -anchor => 'w' ); $hl->headerCreate( 1, -itemtype => 'window', -widget => $label2 ); #... $bottomframe->Button( -text => "Add item", -command => \&add_item ) ->pack( -side => 'right', -anchor => 'ne', -fill => 'x' ); $bottomframe->Button( -text => "Clear", -command => \&clear ) ->pack( -side => 'right', -anchor => 'ne', -fill => 'x' ); $mw->RefontTree( -font => $font ) if defined $font; # set default font my $style = $hl->ItemStyle( 'text', -background => 'light green', -font => $font, ); add_item(); sub add_item { my $e = $hl->addchild(''); if (defined $font) { my $font_descriptive = $mw->GetDescriptiveFontName($font); $style->configure( -font => $font ); print $font_descriptive, "\n"; } $hl->itemCreate( $e, 0, -text => 'Col0', -style => $style ); $hl->itemCreate( $e, 1, -text => 'Col1' ); } sub clear { $hl->delete('all'); } MainLoop;

This way changing the font of the widget is not needed anymore.


In reply to Re^5: perl tk frame packing question by stefbv
in thread perl tk frame packing question by ghosh123

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2021-12-05 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?