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', ); } } #### sub Popup { my $w = shift; $w->configure(@_) if @_; $w->idletasks; my ($mw,$mh) = ($w->reqwidth,$w->reqheight); my ($minwidth,$minheight) = $w->minsize; #ADD $mw = $minwidth if (defined $minwidth and $minwidth > $mw); #ADD $mh = $minheight if (defined $minheight and $minheight >$mh); #ADD my ($rx,$ry,$rw,$rh) = (0,0,0,0); ...