Thread toplevel in bildschirmmitte positionieren (9 answers)
Opened by helmut at 2003-10-05 01:24

esskar
 2003-10-05 15:54
#44522 #44522
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
oder am parent ausrichten, falls vorhanden:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}

View full thread toplevel in bildschirmmitte positionieren