Leser: 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl -w use strict; use Tk; use Tk::LabFrame; use Tk::Pane; my $self = {}; $self->{'mw'} = tkinit(); my $fr_lframe = $self->{'mw'}->LabFrame(-label => 'Friends') ->pack(-side => 'bottom', -fill => 'x'); $self->{'wgt'}->{'fr_frame'} = $fr_lframe->Scrolled('Frame', -scrollbars => 'oe', -background => 'red') ->pack(-side => 'top', -fill => 'both', -expand => 1); update_friends($self); MainLoop; sub update_friends { my $self = shift; $self->{'wgt'}->{'fr_frame'}->Label(-text => 'test')->pack(-side => 'left'); }
Tk::Pane-sticky => style
If Pane is larger than its requested dimensions, this option may be used to position (or stretch) the slave within its cavity. Style is a string that contains zero or more of the characters n, s, e or w. The string can optionally contains spaces or commas, but they are ignored. Each letter refers to a side (north, south, east, or west) that the slave will "stick" to. If both n and s (or e and w) are specified, the slave will be stretched to fill the entire height (or width) of its cavity.
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
#!/usr/bin/perl -w use strict; use Tk; use Tk::LabFrame; use Tk::Pane; my $self = {}; $self->{'mw'} = tkinit(); my $fr_lframe = $self->{'mw'}->LabFrame(-label => 'Friends') ->pack(-side => 'bottom', -fill => 'x'); $self->{'wgt'}->{'fr_frame'} = $fr_lframe->Scrolled('Frame', -scrollbars => 'oe', -background => 'red', -sticky => 'nsew') ->pack(-side => 'top', -fill => 'both', -expand => 1); update_friends($self, 'list#test_user#freddy#erik#klaus#dieter#peter'); MainLoop; sub update_friends { my $self = shift; my $msg = shift; if ($msg =~ /^list#(.*)/) { my @friend_list = sort split /#/, $1; $self->{'wgt'}->{'fr_frame'}->gridPropagate(0); my ($row, $col) = (0, 0); for my $friend (@friend_list) { print "R: $row | C: $col\n"; $self->{'wgt'}->{'fr_frame'}->gridRowconfigure($row, -weight => 1); $self->{'wgt'}->{'fr_frame'}->Label(-text => "- $friend", -font => 'Arial 7.5', -foreground => 'blue', -justify => 'left') ->grid(-row => $row, -column => $col++, -sticky => 'ew'); if ($col > 1) { $col = 0; $row++; } } $self->{'wgt'}->{'fr_frame'}->gridColumnconfigure(0, -weight => 1); $self->{'wgt'}->{'fr_frame'}->gridColumnconfigure(1, -weight => 1); } }
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
#!/usr/bin/perl -w use strict; use Tk; use Tk::LabFrame; use Tk::Pane; my $self = {}; $self->{'mw'} = tkinit(); my $fr_lframe = $self->{'mw'}->LabFrame(-label => 'Friends') ->pack(-side => 'bottom', -fill => 'x'); $self->{'wgt'}->{'fr_frame'} = $fr_lframe->Scrolled('Frame', -scrollbars => 'oe', -background => 'red', -sticky => 'nsew') ->pack(-side => 'top', -fill => 'both', -expand => 1); update_friends($self, 'list#test_user#freddy#erik#klaus#dieter#peter'); MainLoop; sub update_friends { my $self = shift; my $msg = shift; if ($msg =~ /^list#(.*)/) { my @friend_list = sort split /#/, $1; $self->{'wgt'}->{'fr_frame'}->gridPropagate(0); my ($row, $col) = (0, 0); for my $friend (@friend_list) { print "R: $row | C: $col\n"; $self->{'wgt'}->{'fr_frame'}->gridRowconfigure($row, -weight => 1); $self->{'wgt'}->{'fr_frame'}->Label(-text => "- $friend", -font => 'Arial 7.5', -foreground => 'blue', -justify => 'left') ->grid(-row => $row, -column => $col++, -sticky => 'ew'); if ($col > 1) { $col = 0; $row++; } } $self->{'wgt'}->{'fr_frame'}->gridColumnconfigure(0, -weight => 1); $self->{'wgt'}->{'fr_frame'}->gridColumnconfigure(1, -weight => 1); } }
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#!/usr/bin/perl -w use strict; use Tk; use Tk::LabFrame; use Tk::Pane; my $self = {}; $self->{'mw'} = tkinit(); my $fr_lframe = $self->{'mw'}->LabFrame(-label => 'Friends') ->pack(-side => 'bottom', -fill => 'x'); # gridRow- bzw. Columnconfigure müssen auf den Frame angewandt werden, nicht auf # das Scrolled, deshalb empfehle ich dir schon hier den Frame zu speichern: $self->{'wgt'}->{'fr_frame'} = $fr_lframe->Scrolled( Frame => -scrollbars => 'oe', -background => 'red', -sticky => 'nsew', )->pack( -side => 'top', -fill => 'both', -expand => 1, )->Subwidget('scrolled'); #!!! update_friends($self, 'list#test_user#freddy#erik#klaus#dieter#peter'); MainLoop; sub update_friends { my $self = shift; my $msg = shift; if ($msg =~ /^list#(.*)/) { my @friend_list = sort split /#/, $1; # ich glaube, damit scrollbars überhaupt erscheinen, muss geometry # propagation aktiviert sein: # $self->{'wgt'}->{'fr_frame'}->gridPropagate(0); my ($row, $col) = (0, 0); for my $friend (@friend_list) { print "R: $row | C: $col\n"; # würden alle spalten gleich viel platz bekommen, hättest du freiraum # zwischen den labels: (falls dies gewünscht ist => # entfernen) #$self->{'wgt'}->{'fr_frame'}->gridRowconfigure($row, -weight => 1); $self->{'wgt'}->{'fr_frame'}->Label( -text => "- $friend", -font => 'Arial 7.5', -foreground => 'blue', -justify => 'left', )->grid( -row => $row, -column => $col++, -sticky => 'ew', ); if ($col > 1) { $col = 0; $row++; } } # damit alles nach oben geschoben wird bekommt die zeile unter den labels # -weight => 1: (es sei denn, die labels sollen in der höhe gleich viel # platz bekommen, dann die nächste zeile auskommentieren) $self->{'wgt'}->{'fr_frame'}->gridRowconfigure( $row+1, -weight => 1 ); $self->{'wgt'}->{'fr_frame'}->gridColumnconfigure(0, -weight => 1); $self->{'wgt'}->{'fr_frame'}->gridColumnconfigure(1, -weight => 1); } }