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

Hello monks, I have been looking around for a widget that can display multiple line text as a button in Tk. For example:
/----------\
|  Hello   |
|  World   |
|  Button  |
\----------/
Something like this:
  • BlockButton(-wrap=>1, -text=>"Hello World Button", -textalign=>"center",-command=>sub{})->pack;
    Thanks for all comments on this in advance.
  • Replies are listed 'Best First'.
    Re: Multiline Tk Button
    by GrandFather (Saint) on Nov 19, 2006 at 21:15 UTC

      Actually you almost had it:

      use strict; use warnings; use Tk; use Tk::Button; my $mw = MainWindow->new (-title => "Test button"); my $forcedWrap = $mw->Button (-text => "Hello\nWorld\nButton",)->pack +(); my $autoWrap = $mw->Button ( -wrap => 50, -text=>"Hello World Button" )->pack (); MainLoop;

      -wrap and -wraplength seem to be synonomous (although I couldn't find that documented). The Tk::options documentation says:

      Switch: -wraplength
      For widgets that can perform word-wrapping, this option specifies the maximum line length. Lines that would exceed this length are wrapped onto the next line, so that no line is longer than the specified length. The value may be specified in any of the standard forms for screen distances. If this value is less than or equal to 0 then no wrapping is done: lines will break only at newline characters in the text.

      DWIM is Perl's answer to Gödel
    Re: Multiline Tk Button
    by thundergnat (Deacon) on Nov 19, 2006 at 21:02 UTC

      I think you are over-thinking things. Why wouldn't something like this be acceptable.

      use strict; use warnings; use Tk; my $mw = MainWindow->new; my $button = $mw->Button( -text => "Hello\nWorld\nButton", )->pack; MainLoop;