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

Hello there :-) I often use $window->messageBox(..) to show dialogs. This works fine but the text is to near to the icon. I put 5 or more blanks in front of each row to get more space between the icon and the message text. Is there a way to change the Widget? I searched at the Tk.pm and found the Dialog.pm but every changes i made there ($pad1 -> padx option) has no effect.

Replies are listed 'Best First'.
Re: Tk-messageBox -padx
by choroba (Cardinal) on Jul 31, 2013 at 14:46 UTC
    The following code
    use strict; use warnings; use Tk; my $msg ='MainWindow'->new->messageBox( -icon => 'info', -title => 'MSG', -message => '| | | | | | | | | | | | | | | | | | | | | | | | | + | | | | | | | | | | | |', ); MainLoop();

    leads to this window. Is the problem you mention present in the picture?

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Tk-messageBox -padx
by mtmcc (Hermit) on Jul 31, 2013 at 15:31 UTC
    I'm not a tk wizard by any means. Chapter 14 in Mastering perl/Tk describes how to subclass widgets, which might allow you to add the space you want.

    Another possibility (and I'm open to correction on this) might be to write a subroutine that launches your message box, allowing you to automatically add the space you're looking for. Maybe something like this:

    #!/usr/bin/perl use strict; use warnings; use Tk; my $mw = MainWindow -> new; my $result = messengerBox ('question', 'Hello World etc', 'PopUpBox', +'AbortRetryIgnore', 'Retry' ); print STDERR "$result\n"; MainLoop; sub messengerBox { my $icon = $_[0]; my $message = $_[1]; my $title = $_[2]; my $type = $_[3]; my $default = $_[4]; $message = ' Add the space here ' . "$message"; my $response = $mw->messageBox(-icon => $icon, -message => $me +ssage, -title => $title, -type => $type, -default => $default); return $response; }

    But I guess a mega-widget would be the preferred method.

    I hope that's of some help.
Re: Tk-messageBox -padx
by kcott (Archbishop) on Jul 31, 2013 at 21:45 UTC

    G'day kean,

    I have no idea what you mean by "I put 5 or more blanks in front of each row". Tk::messageBox doesn't deal with rows. You've failed to post your code that presumably does use rows in some way.

    I have no idea what you mean by "$pad1 -> padx option". Tk::messageBox documentation makes no mention of $pad1 nor does it have a padx option. You've failed to post your code that presumably does use those in some way.

    Please read How do I post a question effectively? paying particular attention to what it says about posting your code.

    Tk::messageBox provides a quick-and-dirty way to pop-up a message window and get a user response. It has no bells and whistles; it doesn't return a widget you can programmatically interact with. All it provides is six pre-defined sets of buttons, four icons (assuming you want platform independence), and options (each taking a single string) to specify a title, a message and a default button: that's it!

    If you want to customise your message windows, you'll need to use something like Tk::Dialog or Tk::DialogBox. With either of those, look at their ADVERTISED WIDGETS sections to see the parts of the widget you can access and configure with your preferences. See Tk::mega - Subwidget for information on how to get such access.

    -- Ken

Re: Tk-messageBox -padx
by mtmcc (Hermit) on Jul 31, 2013 at 11:51 UTC
    If you post some code, it makes it easier for people to help you.

    As far as I'm aware, padx is an option of pack(), as opposed to an option of messageBox() itself.

      "As far as I'm aware, padx is an option of pack(), as opposed to an option of messageBox() itself."

      Just to clarify that:

      -- Ken

        Thanks Ken!
      I can post the code i found at Tk.pm and Dialog.pm: Tk.pm
      sub messageBox { my ($widget,%args) = @_; # remove in a later version: if (exists $args{'-text'}) { warn "The -text option is deprecated. Please use -message instead"; if (!exists $args{'-message'}) { $args{'-message'} = delete $args{'-text'}; } } $args{'-type'} = (exists $args{'-type'}) ? lc($args{'-type'}) : + 'ok'; $args{'-default'} = lc($args{'-default'}) if (exists $args{'-default' +}); ucfirst tk_messageBox(-parent => $widget, %args); }
      sub Methods { my ($package) = caller; no strict 'refs'; foreach my $meth (@_) { my $name = $meth; *{$package."::$meth"} = sub { shift->WidgetMethod($name,@_) }; } } my %dialog = ( tk_chooseColor => 'ColorDialog', tk_messageBox => 'MessageBox', ...
      sub MessageBox { my ($kind,%args) = @_; require Tk::Dialog; my $parent = delete $args{'-parent'}; my $args = \%args; $args->{-bitmap} = delete $args->{-icon} if defined $args->{-icon} +; $args->{-text} = delete $args->{-message} if defined $args->{-mess +age}; $args->{-type} = 'OK' unless defined $args->{-type}; my $type; if (defined($type = delete $args->{-type})) { delete $args->{-type}; my @buttons = grep($_,map(ucfirst($_), split(/(abort|retry|ignore|yes|no|cancel|ok)/, lc($type)))); $args->{-buttons} = [@buttons]; $args->{-default_button} = ucfirst(delete $args->{-default}) if defined $args->{-default}; if (not defined $args->{-default_button} and scalar(@buttons) == 1 +) { $args->{-default_button} = $buttons[0]; } my $md = $parent->Dialog(%$args); my $an = $md->Show; $md->destroy if Tk::Exists($md); return $an; } } # end messageBox
      Then in Dialog.pm:
      sub MessageBox { my ($kind,%args) = @_; require Tk::Dialog; my $parent = delete $args{'-parent'}; my $args = \%args; $args->{-bitmap} = delete $args->{-icon} if defined $args->{-icon} +; $args->{-text} = delete $args->{-message} if defined $args->{-mess +age}; $args->{-type} = 'OK' unless defined $args->{-type}; my $type; if (defined($type = delete $args->{-type})) { delete $args->{-type}; my @buttons = grep($_,map(ucfirst($_), split(/(abort|retry|ignore|yes|no|cancel|ok)/, lc($type)))); $args->{-buttons} = [@buttons]; $args->{-default_button} = ucfirst(delete $args->{-default}) if defined $args->{-default}; if (not defined $args->{-default_button} and scalar(@buttons) == 1 +) { $args->{-default_button} = $buttons[0]; } my $md = $parent->Dialog(%$args); my $an = $md->Show; $md->destroy if Tk::Exists($md); return $an; } } # end messageBox
        I can post the code i found at Tk.pm and Dialog.pm

        No thanks. Posting your code would be helpful, though.

        I can post the code i found at Tk.pm and Dialog.pm: Tk.pm

        lol