alw has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to change the font for only a part of a label or checkbutton text string? I can't find an example of that anywhere.

Replies are listed 'Best First'.
Re: perl/Tk font question
by zentara (Cardinal) on May 01, 2005 at 19:40 UTC
    That is the first time I've ever heard that question asked. You might be able to pack some labels together, with no padding, and have different fonts in each one. Or you could make a custom image, and use that.

    I'm not really a human, but I play one on earth. flash japh
      I'm surprised that nobody ever wanted to make a word or phrase stand out in a text string. I do it all the time in html with the CGI strong or font functions(or css) but I guess that there is no easy way to do this in Tk. Thanks for the replies.

        I always got the impressoin that this type of thing was done pretty much as above - you create separate graphical elements to encapsulate each change in font. This is likely closely linked to how tags (whether HTML or proprietary or other) work as well: you begin a block, and then end it, and each block gets to be its own graphical element.

        It certainly can be done, and the complexity depends on what you call easy :-)

        Using the standard label/button widgets, it can't be done because those accept simple text.

        However, you can create widgets of your own in Tk, and you can subclass a Button/whatever if you want.

        Then you can implement whichever display/graphic you want, really. You can use Rich Text capabilities in there, etc.

        A label is trivial - a region with text drawn on it. Button is now much harder - the same region, just bounded in a way that makes it feel 3D and responds to mouse clicks.

Re: perl/Tk font question
by Popcorn Dave (Abbot) on May 01, 2005 at 19:37 UTC
    In Tk or HTML? It would help if you specified what you're after.

    In Tk, it should be theoretically possible, but I don't think you could in HTML unless you had a graphic for your button and did it prior to display.

    Update: Apologies for my response. I somehow missed the node title and looked only at the question.

    Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
Re: perl/Tk font question
by splinky (Hermit) on May 02, 2005 at 13:50 UTC
    As other responders have noted, you're limited to straight text in labels - regular labels, button labels, checkbutton labels, etc.

    In some cases, you can make do by using a text widget, which allows a lot more freedom in formatting. This works particularly well as a replacement for a regular label. But that's less useful for things like checkbuttons, because a checkbutton label is clickable, and your text widget wouldn't behave like that by default. You'd have to bind it manually.