You have errors in the code you posted, so it will not compile.
From your question I understand, that you want to present a Dialog window, without opening a MainWindow at the same time.
It is necessary for a Tk application to instantiate a Tk::MainWindow
that serves as a root in the applications window hierarchy. However it is not required to actually display this window.
If you want to hide your MainWindow you call ->withdraw
on it like so:
use strict;
use warnings;
use Tk;
my $mw= MainWindow->new;
$mw->withdraw;
my $response = $mw->messageBox(-title => 'Title',
-message => 'Message',
-type => 'YesNo',
-icon => 'question',
-default => 'yes');
print "$response\n";
Note that the messageBox call blocks until the user clicks a button. MessageBox calls into the event loop as needed, so you don't have to start the application by calling MainLoop()