I need to display a message box after a user clicks on a button. For some reason, I can't seem to get this code to work. Any help is much appreciated.

The text "before\n" is printed, but the dialog is not displayed.

#! /usr/bin/perl -w # use strict; use warnings "all"; use Tk; use Tk::Dialog; our $mw = new MainWindow; my $f_select = $mw->Frame( -bd=>2, -relief=>'groove') ->pack(-side=>'l +eft', -fill=>'y'); my $f_refresh = $f_select->Frame() ->pack(-side=>'bottom', -fill=>'x') +; $f_refresh->Button(-text => 'Test', -command => sub {displayMsg()}) -> +pack(-side=>'left'); # This one works. $mw->Dialog(-title => "Test", -text => "My test Message", -bitmap=>'qu +estion', -buttons => ['Ok'])->Show(); MainLoop; exit; # Should never actually get here. sub displayMsg { print "before\n"; # for some reason, Dialog() does not work from this context. # $mw->Dialog(-title => "Error", -text => "My Error Message", -bit +map=>'error', -buttons => ['Ok'])->Show(); my $dialogWindow = $mw->Dialog(-title => "Error", -text => "My Err +or Message", -bitmap=>'error', -buttons => ['Ok']); $dialogWindow->Show(); # neither does messageBox :-( #my $answer => $mw->messageBox(-title => 'Please Reply', # -message => 'Would you like to continue?', # -type => 'YesNo', -icon => 'question', -default => 'yes'); print "after\n"; }

In reply to Can't get Dialog or messageBox to work from button by SwaJime

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.