Monday, 17 February 2014

Perl Message Box Tutorial

Previously, we covered the Perl Listbox example using the Tk module. In this post, we will discuss about using Tk to create a simple Message Box.

First of all, install the Tk Msgbox module from the command line as follows:

sudo cpan Tk::MsgBox

Then consider the following code snippet : 

---------------------------------------------------------

use Tk;
use Tk::MsgBox;

my $m = MainWindow->new;

my $x = $m->MsgBox(
-title=> 'Perl MsgBox Example'
-message=> "Welcome to Tk Message Box"
-type=> 'okcancel'
);

my $button = $x->Show;

---------------------------------------------------------

The output window will be as follows :


In above example, we've used the okcancel box type. The msgbox type can be changed to one of the following : ok, okcancel, yesno, yesnocancel, retrycancel, abortretrycancel.

Even the info icon can be changed to error, warning types if needed.


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker