Hi, I'd like to use the -font option in a Tk Label if the font's been externally defined by the user. I'd also like to condense my lines of code by combining options I'm repeating. So I'd like something like this:
my $newfont = '';
# maybe font value read from user, results in
# $newfont = "{liberation sans} 8 normal";
my $opt = "-fg => $fg, -bg => $bg";
$opt .= ", -font => $newfont" if length($newfont);
$rw->Label(-text => "Col. 1", $opt, -padx => 10)->grid(
$rw->Label(-text => "Col. 2", $opt, -padx => 11),
$rw->Label(-text => "Col. 3", $opt, -padx => 11))
but I get this error message:
Tk::Error: Odd number of args to Tk::Label->new(...)
Nothing I could think of, including escaped quotes or eval(), has gotten around it, so for now I use an if-else that checks length($newfont) and repeats the Label widget creation, once with and once without -font.
Is this possible? I lack detailed perl knowledge, so probably something like \$${opt} would do the trick :-) Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.