#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); $mw->optionAdd("*font", "Arial 15 normal"); $mw->geometry("+250+200"); $mw->title("Example of Custom Dialog-Window"); my $btn1 = $mw->Button(-text => "Click button to open dialog-window.", -command => \&btnClick); $btn1->pack(-padx => 20, -pady => 20); my $btn2 = $mw->Button(-text => "Exit", -command => sub {$mw->destroy()}); $btn2->pack(-pady => 10); MainLoop(); sub btnClick { my $dialogwindow = $mw->Toplevel(); $dialogwindow->title("Dialog Window"); $dialogwindow->geometry("+300+250"); my $lab1 = $dialogwindow->Label(-text => "Please enter something:"); $lab1->pack(); my $entr1 = $dialogwindow->Entry(); $entr1->pack(); $entr1->focus(); my $btn3 = $dialogwindow->Button(-text => "Ok", -command => sub {dialogEnd($dialogwindow, $entr1)}); $btn3->pack(); # This is the important line: It tells the main-window to wait: $mw->waitWindow($dialogwindow); } sub dialogEnd { my $dialogwindow = shift; my $entr1 = shift; my $result = $entr1->get(); $dialogwindow->destroy(); $mw->messageBox(-title => "Input", -type => "OK", -message => "You entered:\n\n$result\n"); }