Thread Widgets ändern (3 answers)
Opened by J-jayz-Z at 2005-09-20 10:57

J-jayz-Z
 2005-09-21 12:02
#44599 #44599
User since
2005-04-13
625 Artikel
BenutzerIn
[Homepage] [default_avatar]
Okay, so geht es:
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
#!/usr/bin/perl
use strict;
use warnings;

use Tk;

my %widget;
my $text;
my $temp = 1;

$widget{main} = MainWindow->new();
$widget{frame} = $widget{main}->Frame(-width => 65, -height => 20);
$widget{frame}->packPropagate(0);
$widget{frame}->pack(-side => 'top');
$widget{label} = $widget{frame}->Label(-textvariable => \$text);
$widget{exit} = $widget{main}->Button(-text => 'quit', -command => sub { $widget{main}->destroy(); });
$widget{change} = $widget{main}->Button(-text => 'change', -command => \&change);
$widget{entry} = $widget{frame}->Entry(-textvariable => \$text);

$widget{label}->pack(-side => 'top');
$widget{exit}->pack(-side => 'right');
$widget{change}->pack(-side => 'left');

MainLoop();

sub change {
if($temp) {
    $widget{label}->packForget();
    $widget{entry}->pack(-side => 'top');
    $temp = 0;
} else {
    $widget{entry}->packForget();
    $widget{label}->pack(-side => 'top');
    $temp = 1;
    }
}


EDIT: Mit packPropagate(0) ist es schöner...\n\n

<!--EDIT|J-jayz-Z|1127292098-->
perl -Mstrict -Mwarnings -e 'package blub; sub new { bless {} } sub bar {my $self=shift; $self->{bla}="5065726c2d436f6d6d756e697479"; return $self->{bla};} my $foo=blub->new();print "Hallo ";print pack("H*",$foo->bar()); print "\n"'

http://perl-tutor.de

View full thread Widgets ändern