> Could somebody point me in the right direction of making a dialog where if
> they click ok it goes ahead and closes the program but if they click cancel
> it goes back. I'm new to wxPerl I've tried copying some of the source from
> the dialogs sample but it doesn't work, this is what I got:
>
> sub OnQuit {
> my( $this, $event ) = @_;
>
> my $dialog = Wx::MessageBox( 'Exiting Worms GUI!', 'Message',
> wxOK|wxCANCEL, $this);
Wx::MessageBox is a function that shows a message box, and then
returns one of wxYES, wxNO, wxCANCEL, wxOK, depending on what
button the user pressed: it returns an integer, not
a dialog object, and you can't call a method on an integer.
> if( $dialog->ShowModal == wxID_CANCEL ) {
> $dialog->Destroy;
Wx::MessageBox does not return a dialog: no need to destroy it.
> } else {
> $this->Close( 1 );
> }
> }
>
> When I click either Ok or Cancel, I get this error:
>
> Can't call method "ShowModal" without a package or object reference at
> test3.pl
> line 72.
sub OnQuit {
my( $this, $event ) = @_;
my $dialog = Wx::MessageBox( 'Exiting Worms GUI!', 'Message',
wxOK|wxCANCEL, $this);
if( $dialog != wxID_CANCEL ) {
$this->Close( 1 );
}
}
You could as well use Wx::messageDialog directly
( as suggested in another post ).
Regards
Mattia
|