Thread TopLevel-Fenster schließen, wenn Klick außerhalb (14 answers)
Opened by Gast at 2008-01-10 15:32

Gast Gast
 2008-01-14 18:18
#104718 #104718
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl

use strict;
use warnings 'all';

use Tk;
use Tk::KMenu;

# create main window
my $mw = tkinit();

# create menu
my $menu = new Tk::KMenu $mw;

# add menu entries
$menu -> add(
Test => sub {
print "Test\n";
},
Test2 => sub {
print "Test 2\n";
},
Delete => sub {
$menu -> del( 0 .. 2 );
},
Beenden => sub {
$mw -> destroy;
},
);

# should create a package for MenuButtons, so that the following can be written simpler
#
# create menubutton
#
my $menubutton = $mw -> Button(
-text => 'Open Menu',
) -> pack;

# have to split this because $menubutton has to be defined,
# so we can use it in the -command callback.
$menubutton -> configure(
-command => sub {
$menu->show(
$mw->rootx + $menubutton->x, # calculate the x position
$mw->rooty + $menubutton->y # calculate the y position
+ $menubutton->reqheight,
);
},
);

MainLoop;


MfG Horst

View full thread TopLevel-Fenster schließen, wenn Klick außerhalb