Thread TK::Listbox : Mehrere Einträge in einer Zeile (5 answers)
Opened by YAPD at 2015-10-22 16:31

YAPD
 2015-10-26 16:49
#182716 #182716
User since
2015-09-20
146 Artikel
BenutzerIn

user image
Hallo Zusammen,

ich stelle Euch hier meine Lösung für eine MListBox in einer Perl TK
Oberfläche vor. Besonders ist die Einbindung eines Popup Menus in der
MListBox & einer ScrollBar :

# -------------------------------------------------------------------

Als Erstes die Erstellung des Basis Scripts :

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
#!/usr/bin/perl

# ------------------------------------------------------------------------------------------

use strict;
use warnings;

use Tk;
use utf8;

# ------------------------------------------------------------------------------------------

my $Haupt_Fenster;
my $mlistbox_inhalte;
my @auflistung_mlistbox_details;

------------------------------------------------------------------------------------------

&Haupt_Fenster( );

# ------------------------------------------------------------------------------------------

sub Haupt_Fenster {

$Haupt_Fenster = MainWindow -> new;

my $Breite = 640;
my $Hoehe = 480;

$Haupt_Fenster -> geometry( $Breite . 'x' . $Hoehe );
$Haupt_Fenster -> update;

my $Top_Level = $Haupt_Fenster -> toplevel;
}


Plazierung des Frames & des Labels für die MListBox :

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my $mlistbox_label = $Haupt_Fenster -> Label( -text   => "" , 
-background => "white" ,
-height => 16 ,
-width => 140 ,
-relief => 'groove' ,
-anchor => "n"

) -> place( -x => 250 , -y => 83 );

my $mlistbox_frame = $Haupt_Fenster -> Frame( -background => 'white' ,
-borderwidth => 0 ,
-width => 842 ,
-height => 210 ,
-relief => 'groove'

) -> place( -x => 251 , -y => 85 );


Plazierung der MListBox innerhalb des Frames & Definierung der Parameter für die MListBox wie Farbe, Breite, Höhe etc. :

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
use Tk::MListbox;

$mlistbox_inhalte = $mlistbox_frame -> MListbox ( -background => 'white' ,
-borderwidth => '0' ,
-columns => [ [ -text => 'Laufende Nr.' , -resizeable => 0 , -sortable => 1 , -height => 12 , -width => 15 , -borderwidth => 0 ] ,
[ -text => 'Bezeichnung' , -resizeable => 1 , -sortable => 1 , -height => 12 , -width => 15 , -borderwidth => 0 ] ,
[ -text => 'Geburtstag' , -resizeable => 0 , -sortable => 1 , -height => 12 , -width => 15 , -borderwidth => 0 ] ,
[ -text => 'Verfügbar' , -resizeable => 0 , -sortable => 1 , -height => 12 , -width => 15 , -borderwidth => 0 ] ,

] ,

-configurecommand => '1' ,
-cursor => 'plus' ,
-font => 'Times 8' ,
-foreground => 'black' ,
-height => 15 ,
-highlightcolor => 'pink' ,
-highlightbackground => 'white' ,
-moveable => '1' ,
-relief => 'groove' ,
-resizeable => '0' ,
-selectborderwidth => '1' ,
-selectbackground => 'black' ,
-selectforeground => 'yellow' ,
-selectmode => 'single' ,
-separatorcolor => 'black' ,
-sortable => '1' ,
-width => '930' ,

) -> place( -x => 0 , -y => 0 );


Einbindung & Plazierung der ScrollBar für dieMlistBox :

Code: (dl )
1
2
3
4
5
my $scrollbar = $mlistbox_inhalte -> Scrollbar( -orient => "vertical" );
$scrollbar -> place( -x => 833 , -y => 1 , -height => 207 , -width => 10 );

$mlistbox_inhalte -> configure( -yscrollcommand => [ 'set' , $scrollbar ] );
$scrollbar -> configure( -command => [ 'yview' => $mlistbox_inhalte ] );


Bespiel - Einträge für die Verwendung der MListBox :

Code: (dl )
1
2
3
4
5
$mlistbox_inhalte -> insert( 'end' , [ "1000" , "Datensatz 1" , "01.01.2015" , "Sofort" ] );
$mlistbox_inhalte -> insert( 'end' , [ "1001" , "Datensatz 2" , "01.01.2015" , "Sofort" ] );
$mlistbox_inhalte -> insert( 'end' , [ "1002" , "Datensatz 3" , "01.01.2015" , "Sofort" ] );
$mlistbox_inhalte -> insert( 'end' , [ "1003" , "Datensatz 4" , "01.01.2015" , "Sofort" ] );
$mlistbox_inhalte -> insert( 'end' , [ "1004" , "Datensatz 5" , "01.01.2015" , "Sofort" ] );


Nun das entscheidene Binding für das Popup - Menu :

Code: (dl )
$mlistbox_inhalte -> bindRows( "<Button-3>" , [ \&mlistbox_inhalte_popups ] );


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
sub mlistbox_inhalte_popups {

my ( $w, $infoHR ) = @_;

my $menu = $w -> Menu( -tearoff => 0 );
my $index = $infoHR -> { '-column' };

print "Ausgewaehlte Reihe : " . $infoHR -> { -row } . "\n" .
"Ausgewaehlte Zeile : " . $infoHR -> { -column } . "\n" ;

my @auflistung_mlistbox = $w -> curselection;

foreach( @auflistung_mlistbox )
{
@auflistung_mlistbox_details; = $w -> getRow( $infoHR -> { -row } );

$menu -> add( 'command', -label => "Hide " . $w -> columnGet( $index ) -> cget( -text ) ,
-command => sub { $w -> columnHide( $index ); }
);

$menu -> add( 'separator' );
}


foreach ( $w -> columnGet( 0, 'end' ) )
{
unless ( $_ -> ismapped )
{
$menu -> add( 'command' , -label => "Show " . $_->cget( -text ) ,
-command => [ $w => 'columnShow', $_ ,
-before => $index ] ,
);
}
}

$menu -> Popup( -popover => 'cursor' );

}


Viele Grüße
YAPD
Last edited: 2015-10-26 17:09:46 +0100 (CET)
Yet Another Perl Developer

View full thread TK::Listbox : Mehrere Einträge in einer Zeile