sub CenterWidget { my $widget = shift; $widget->update(); my $parent = $widget->parent(); my($pwidth, $pheight, $px, $py) = (0, 0, 0, 0); if($parent) { $pwidth = $parent->width; $pheight = $parent->height; $px = $parent->x; $py = $parent->y; } else { $pwidth = $widget->screenwidth; $pheight = $widget->screenheight; } my $wwidth = $widget->width; my $wheight = $widget->height; my $posx = $px + int(($pwidth / 2) - ($wwidth / 2)); my $posy = $py + int(($pheight / 2) - ($wheight / 2)); $widget->geometry($wwidth . 'x' . $wheight . '+' . $posx . '+' . $posy); }