1
2
3
4
5
6
7
8
[section1]
testvar1 = 1
testvar2 = 2
[section2]
testvar1 = 1
testvar2 = 2
testvar3 = 3
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
use strict; use warnings; use Config::Tiny; use Tk::BrowseEntry; use Tk; my $Config = Config::Tiny->new(); $Config = Config::Tiny->read( 'test.ini' ); my @section; foreach my $key (sort keys %{$Config}){ push(@section, $key); } my $mw = new MainWindow; my $frm_ini = $mw -> Frame(); my $lbl_title = $mw->Label ( -text=>"ini-editor", -font => [-size => 12, -weight => "bold"]); my $btn_browse= $mw->Button( -text=>"Anzeigen",-command=>\&create_editor); my $browse_select = ""; my $browse_value = $mw->BrowseEntry(-variable => \$browse_select, -command=>sub {}); for(my $i=0; $i<=$#section; $i++){ $browse_value->insert("end", $section[$i]); } $lbl_title->grid ( -row=>0,-column=>0, -columnspan=>3); $browse_value->grid(-row=>1,-column=>0, -sticky => "w"); $btn_browse->grid( -row=>1,-column=>1, -columnspan=>2, -sticky=>"e"); MainLoop(); sub create_editor { my $frm_editor = $mw -> Frame(); if ($browse_select eq ""){ return 0; } my @labels = (); my @inputs = (); my @buttons = (); my @new_value; my $count = 0; foreach my $attr(sort keys %{$Config->{$browse_select}}){ $labels[$count] = $frm_editor->Label ( -text=>$attr); $new_value[$count] = $Config->{$browse_select}{$attr}; $inputs[$count] = $frm_editor->Entry (-textvariable => \$new_value[$count]); $buttons[$count] = $frm_editor->Button( -text=>"Edit", -command=>\&Test); $count++; } my $label; my $input; my $button; my $row = 3; $frm_editor -> grid(-row=>2,-column=>0, -columnspan=>2, -sticky => "w"); for (my $count = 0; $count < scalar(@labels); $count++){ $label = $labels[$count]; $input = $inputs[$count]; $button = $buttons[$count]; $label->grid(-row => 2 + $count, -column=> 0, -sticky => "w"); $input->grid(-row => 2 + $count, -column=> 1, -sticky => "w"); $button->grid(-row => 2 + $count, -column=> 2, -sticky => "w"); } } sub Test{ }
1 2 3 4 5
my $mw = MainWindow->new; my $fr = $mw->Frame->pack; $fr->Label( -text=>'hallo' )->pack; ... $fr->destroy;
$fr->Button(-text=>'x',-command=> sub{ funktionX($para); })->pack;
$fr->Button(-text=>'x',-command=>[\&funktionX,$para] )->pack;
$fr->Button(-text=>'x',-command=>['funktionX',$para] )->pack;