use strict; use warnings; use Tk; my $mw = MainWindow -> new; $mw -> minsize (qw(600 400)); my $button = $mw -> Button ( -text => 'Center of screen', -command => sub {popup('screen')}, ) -> pack; my $other_button = $mw -> Button ( -text => 'Center of main window', -command => sub {popup('window')}, ) -> pack; MainLoop; sub popup { my $type = $_[0]; my $popup = $mw -> Toplevel; $popup -> withdraw; for (1..10) { my $label = $popup -> Label ( -text => "This is a label $_", ) -> pack; } if ($type eq "screen") { $popup -> Popup(); } else { $popup -> Popup ( -popover => $mw, -overanchor => 'c', -popanchor => 'c', ); } }