#!/bin/env perl
# tk_window_center.pl
# appleii
# 2010.07.01
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new();
$mw->Button(-text => "click", -command => [\¢er_me, $mw])->pack();
MainLoop();
sub center_me
{
my ($mw) = @_;
if ($mw->geometry() =~ /(\d+)x(\d+)/)
{
my ($width, $height) = ($1, $2);
my ($x, $y) = (int(($mw->screenwidth() - $width) / 2), int(($mw->screenheight() - $height) / 2));
$mw->geometry("${width}x${height}+${x}+${y}");
}
}
|