Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: How to get foreground color from a TK::Listbox

by jsteng (Beadle)
on Apr 14, 2018 at 14:12 UTC ( #1212873=note: print w/replies, xml ) Need Help??


in reply to Re: How to get foreground color from a TK::Listbox
in thread How to get foreground color from a TK::Listbox

:) Seems there is no solution for font flipflopping? Will work around this. thanks!
  • Comment on Re^2: How to get foreground color from a TK::Listbox

Replies are listed 'Best First'.
Re^3: How to get foreground color from a TK::Listbox
by zentara (Archbishop) on Apr 15, 2018 at 11:43 UTC
    Hi, the Listbox is a very useful widget, but has it's limitations. I would suggest making your own widget on a Tk::Canvas. The Canvas allows you to do almost anything you want. I made a little Canvas based demo widget module to show how easy it is.... see Tk-CanvasDirTree. It shows how to easily import a list and display it anyways you want. If you want full control over colors and fonts and bindings, the Tk::Canvas is the way to go. The only real trick is measuring your font size in pixels, which is easy to do. Make your own wheel! :-)
      OK! Seems like a good place to finally solve my project.
      Will work on a canvas solution and see how that goes from there on. Thanks.
        Hi, one point I forgot to mention. It may or may not help. In Tk, is is sometimes useful to pre-define all the special fonts before you use them in widgets. Create the fonts first, then refer to them by a name, like 'big', or 'bold'.
        #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=> 28 ); my $c = $mw->Canvas(-bg=>'white')->pack; #---determine font spacing by making a capital W--- my $fonttest = $c->createText(100,100, -fill => 'black', -text => 'W', -font => 'big' ); my ($bx,$by,$bx1,$by1) = $c->bbox($fonttest); $c->{'f_width'} = $bx1 - $bx; $c->{'f_height'} = $by1 - $by; print 'width ',$c->{'f_width'},' ',$c->{'f_height'},"\n"; MainLoop;

        I'm not really a human, but I play one on earth. ..... an animated JAPH

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1212873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2020-10-25 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?