Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]5199[/thread]

Hilfe bei einer Sub...: ich komm nicht so ganz weiter...



<< |< 1 2 >| >> 14 Einträge, 2 Seiten
zipster
 2006-06-02 12:16
#45551 #45551
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Hi,

ich hänge momentan ziemlich fest und hoffe ihr könnt mir irgendwie weiterhelfen oder wenigstens ein paar gute Ideen geben. *Renee und PTK und... anschau ;) *

Also Fehler oder so was habe ich nicht, weiß einfach nur nicht wie ich's umsetzten soll.

Ich bau ein Fenster auf und würde hierfür gern eine sub schreiben.
Da es aber ziemlich viel unterschiede in den sonst gleichen Befehlen gibt weiß ich nicht so recht wie ich's umsetzten soll.

Jetzt erstmal ein kleiner Bespiel Code.

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
52
53
54
55
...
#zeile1
if ( $ref_hash_konfig->{pfeil_zurueck} == '1'){
$frame_kontakte_haupt->Button(-text => '<<', -command => [\&eintrag_zurueck],)->grid(-row=>'0', -column=>'0', -sticky => 'w');
}
if ( $ref_hash_konfig->{nachname} == '1'){
$frame_kontakte_haupt->Label(-text => "Nachname:")->grid(-row=>'0', -column=>'1', -sticky => 'w');
$frame_kontakte_haupt->Entry(-textvariable=> \$ref_hash_haupt->{nachname}, -state => '$ref_hash_berechtigung->{nachname}')->grid(-row=>'0', -column=>'2', -sticky => 'w');
}
else{
$spacer1 = $frame_kontakte_haupt->Photo('-format' => 'png', -file => 'images/spacer1.png');
$frame_kontakte_haupt->Label(-image => $spacer1, -width => "200", -height => "10")->grid(-row=>'0', -column=>'1', -columnspan => '2', -sticky => 'w');
}
if ( $ref_hash_konfig->{vorname} == '1'){
$frame_kontakte_haupt->Label(-text => "Vornamen:")->grid(-row=>'0', -column=>'3', -sticky => 'w');
$frame_kontakte_haupt->Entry(-textvariable=> \$ref_hash_haupt->{vorname})->grid(-row=>'0', -column=>'4', -sticky => 'w');
}
else{
$spacer2 = $frame_kontakte_haupt->Photo('-format' => 'png', -file => 'images/spacer2.png');
$frame_kontakte_haupt->Label(-image => $spacer2, -width => "242", -height => "10")->grid(-row=>'0', -column=>'3', -columnspan => '2', -sticky => 'w');
}
if ( $ref_hash_konfig->{pfeil_vor} == '1'){
$frame_kontakte_haupt->Button(-text => '>>', -command => [\&eintrag_vor])->grid(-row=>'0', -column=>'5', -sticky => 'w');
}
if ( $ref_hash_konfig->{zimmer_bett} == '1'){
$frame_kontakte_haupt->Label(-text => "Zimmer / Bett:")->grid(-row=>'0', -column=>'6', -sticky => 'w');
$frame_kontakte_haupt->BrowseEntry( -variable => \$ref_hash_haupt->{zimmerbett})->grid(-row=>'0', -column=>'7', -sticky => 'w');
}
else{
$spacer3 = $frame_kontakte_haupt->Photo('-format' => 'png', -file => 'images/spacer3.png');
$frame_kontakte_haupt->Label(-image => $spacer3, -width => "232", -height => "10")->grid(-row=>'0', -column=>'6', -columnspan => '2', -sticky => 'w');
}
...
#zeile2
if ( $ref_hash_konfig->{anrede} == '1'){
$frame_kontakte_haupt->Label(-text => "Anrede:")->grid(-row=>'1', -column=>'1', -sticky => 'w');
$frame_kontakte_haupt->BrowseEntry(-variable => \$ref_hash_haupt->{anrede}, -colorstate => 'white',)->grid(-row=>'1', -column=>'2', -sticky => 'w');
}
else{
$spacer1 = $frame_kontakte_haupt->Photo('-format' => 'png', -file => 'images/spacer1.png');
$frame_kontakte_haupt->Label(-image => $spacer1, -width => "200", -height => "10")->grid(-row=>'1', -column=>'1', -columnspan => '2', -sticky => 'w');
}
...
#zeile3
if ( $ref_hash_konfig->{geburtstag} == '1'){
$frame_kontakte_haupt->Label(-text => "Geburtstag:")->grid(-row=>'2', -column=>'1', -sticky => 'w');
$frame_kontakte_haupt->Entry(-textvariable=> \$ref_hash_haupt->{geburtstag})->grid(-row=>'2', -column=>'2', -sticky => 'w');
}
else{
$spacer1 = $frame_kontakte_haupt->Photo('-format' => 'png', -file => 'images/spacer1.png');
$frame_kontakte_haupt->Label(-image => $spacer1, -width => "200", -height => "10")->grid(-row=>'2', -column=>'1', -columnspan => '2', -sticky => 'w');
}
...
#zeile4
...


Ich würde gern folgenden Befehl als sub erstellen lassen
Code: (dl )
1
2
3
4
5
6
7
8
if ( $ref_hash_konfig->{nachname} == '1'){
$frame_kontakte_haupt->Label(-text => "Nachname:")->grid(-row=>'0', -column=>'1', -sticky => 'w');
$frame_kontakte_haupt->Entry(-textvariable=> \$ref_hash_haupt->{nachname}, -state => '$ref_hash_berechtigung->{nachname}')->grid(-row=>'0', -column=>'2', -sticky => 'w');
}
else{
$spacer1 = $frame_kontakte_haupt->Photo('-format' => 'png', -file => 'images/spacer1.png');
$frame_kontakte_haupt->Label(-image => $spacer1, -width => "200", -height => "10")->grid(-row=>'0', -col vonumn=>'1', -columnspan => '2', -sticky => 'w');
}


Ich hänge bei folgenden Bereichen
wie mach ich das wenn ich eine unterschiedliche Anzahl von Wigdetparamter habe (einmal nur "-text" und einmal "-variable", "-colorstate"usw...)????
wie mache ich das wenn ich einmal columnspan dabei habe und einmal nicht????
wie mach ich das wenn ich einmal ein Widget aufrufe und einmal 2????

Vielen Dank

Gruß
Seri aka zipster
esskar
 2006-06-02 13:23
#45552 #45552
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
gibt doch einfach hashrefs als parameter mit!
zipster
 2006-06-02 14:02
#45553 #45553
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Meinst du das ich sowas "-text => 'klar'" per Hashref übergebe?
esskar
 2006-06-02 14:23
#45554 #45554
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
ja!
zipster
 2006-06-02 14:32
#45555 #45555
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Geht leider nicht! :D

Wenn ich das so überebe bekomme ich folgende Fehlermeldung
Quote
Tk::Error: Odd number of args to Tk::Label->new(...)
Tk callback for event
Tk callback for .
Tk callback for .frame
Tk::Widget::new at C:/Perl/site/lib/Tk/Widget.pm line 164
Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/Widget.pm line 256
main::kontakte_haupt_widget at D:\Daten\Arbeit\Programmieren\Perl-Scripte\Plave
do TK\Redesign 1_9\test_fuer_sub.pl line 62
Odd number of args to Tk::Label->new(...)
at D:\Daten\Arbeit\Programmieren\Perl-Scripte\Plavedo TK\Redesign 1_9\test_fuer
_sub.pl line 62


Wenn ich es wie folgt übergebe gehts...
Code (perl): (dl )
....($parmeter => $uebrgabe_wert)...
esskar
 2006-06-02 14:56
#45556 #45556
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
hmm.
zeig mal den code deiner sub
und wie du diese aufrufst!
zipster
 2006-06-02 15:14
#45557 #45557
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Testweise so
Code: (dl )
1
2
3
4
5
6
7
8
9
$frame_kontakte_haupt = $hauptfenster->Frame(-borderwidth => "2")->pack();
my $hash;
$hash->{parameter} = "-text => 'klar'";
&kontakte_haupt_widget($frame_kontakte_haupt, 'Label', \%{$hash});
MainLoop;
sub kontakte_haupt_widget{
my ( $frame, $widget, $hash,) = @_;
$frame->$widget( $hash->{paramter} )->grid();
}


Aber vieleicht reden wir auch aneinander vorbei
esskar
 2006-06-02 15:40
#45558 #45558
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
hmm
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
sub set_label {
   my ( $frame, $use_name, $label, $entry ) = @_;
   if ($use_name) {
       $frame->Label(%$label)
         ->grid( -row => '0', -column => '1', -sticky => 'w' );
       $frame->Entry(%$entry)
         ->grid( -row => '0', -column => '2', -sticky => 'w' );
   }
   else {
       my $spacer1 =
         $frame->Photo( '-format' => 'png', -file => 'images/spacer1.png' );
       $frame->Label( -image => $spacer1, -width => "200", -height => "10" )
         ->grid(
           -row => '0',
           -column => '1',
           -columnspan => '2',
           -sticky     => 'w'
         );
   }
}

my $use_name = $ref_hash_konfig->{nachname} == '1';
set_label(
   $frame_kontakte_haupt,
   $use_name,
   $use_name
   ? (
       { -text => "Nachname:" },
       {
           -textvariable => \$ref_hash_haupt->{nachname},
           -state        => '$ref_hash_berechtigung->{nachname}'
       }
     )
   : ()
);
\n\n

<!--EDIT|esskar|1149248698-->
Strat
 2006-06-02 15:41
#45559 #45559
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
dereferenzieren muesste helfen:
Code: (dl )
1
2
3
$frame->$widget(
%{ $hash->{parameter} }
)->grid();
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
zipster
 2006-06-02 18:34
#45560 #45560
User since
2004-09-06
458 Artikel
BenutzerIn
[default_avatar]
Danke Esskar, aber wenn ich ehrlich sein soll verstehe ich es noch nicht so ganz.Besonders das
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
set_label(
$frame_kontakte_haupt,
$use_name,
$use_name
? (
{ -text => "Nachname:" },
{
-textvariable => \$ref_hash_haupt->{nachname},
-state => '$ref_hash_berechtigung->{nachname}'
}
)
: ()
);
<< |< 1 2 >| >> 14 Einträge, 2 Seiten



View all threads created 2006-06-02 12:16.