1.Display information to the user.
2.Get a simple response from the user (usually a 'yes' or 'no')
Based on that, the information you can get is related to which button they pressed.
If you want a callback sub associated with a button press, you will need to create your own top level window and use the callback methods described by the first poster.
Here is a sample I used for Perlbox because I was not pleased with DialogBox. In short, this is a simple reimplementation of DialogBox, but you could alter it to have the callback functions that you want.
The following code has been released under the GPL License
You could use this Dialog like the following 'calling code", and it would work just like a regular dialog:
my $text="Perlbox Voice ".PBOX_VERSION."\nDecember 2004\nby Sha +ne Mason\n(me\@perlbox.org)\nhttp://perlbox.org"; my $d=$mainwindow->pSimpleDialog(-title => "perlbox",-text =>$t +ext,-OKonly=>'yes'); my $button = $d->Show; if(!$button){ &myCANCEL; } else{ return; }
Or you could alter the module to serve your own (GPL'd, open source) purpose (call back a function in this module, or pass a more meaningful return to the calling code above). Here is the module itself.
As you see, it has two buttons with their own callbacks and IS a top level widget itself. Also, not that this can have 'Yes' and a 'No' or an 'OK' only. Look at the Perlbox source code to get more examples on how to call.package Perlbox::perlboxTK::pDialog::pSimplesDialog; use Tk; use strict; use vars qw( $VERSION @ISA) ; $VERSION = '0.1.x' ; require Tk::Toplevel ; @ISA = qw( Tk::Toplevel ) ; Construct Tk::Widget 'pSimpleDialog' ; my $mw; my ($textVar, $titleVar,$okonly); my $returnVal; return 1; sub Populate(){ my $args; ($mw, $args) = @_; $mw->SUPER::Populate($args); $textVar = delete $args->{"-text"}; $titleVar= delete $args->{"-title"}; $okonly = delete $args->{"-OKonly"}; $mw->protocol( 'WM_DELETE_WINDOW' => sub { } ) ; $mw->transient( $mw->MainWindow ) ; } sub Show(){ #construct the size of our widget my $ht=150; $mw->geometry("200x".$ht."+10+10"); $mw->title($titleVar); my $label=$mw->Label(-text=>$textVar, -wraplength=>190, -font= +>($mw->fontCreate(-family=>"courier",-size=>9)),-anchor=>'w',-justify +=>'left')-> place(-y=>10,-x=>10, -width=>190, -height=>100); if($okonly ne 'yes'){ my $cmdCancel=$mw->Button(-text=>"NO", -relief=>'flat',-com +mand=> sub{&myNo})-> place(-y=>$ht-30,-x=>10,-width=>80, -height=>20); } $mw->waitVariable( \$returnVal ) ; $mw->withdraw ; $returnVal; } sub myYes(){ $returnVal=1; } sub myNo(){ $returnVal=0; }
In reply to Re: Understanding Tk::DialogBox
by scmason
in thread Understanding Tk::DialogBox
by rvosa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |