#!perl use strict; # or punch 2 face use warnings; # or tackle use Tk; my $window = Tk::MainWindow->new(-width=> '0m',-title=> 'Umrechnung'); my $oben = $window->Frame->pack(); my $titel = $oben->Label(-text=>"Programm für die Umrechnung von Grad Celsius" . " in Kelvin und Fahrenheit.")->pack(); my $clean = $window->Frame->pack(); my $empty = $clean->Label(-text=>"")->pack(); $window->Label(-text=>'Anfangswert:')->pack(); my $eingabe = $window->Text(-width=>20,-height=>1,-borderwidth=> '1m', -cursor=> 'left_side',-background=> 'white',-font=>'courierb12', -foreground=> 'black')->pack(); $window->Label(-text=>'Endwert:')->pack(); my $eingabe2 = $window->Text(-width=>20,-height=>1,-borderwidth=> '1m',-cursor=> 'left_side',-background=> 'white',-font=>'courierb12', -foreground=> 'black')->pack(); my $clean2 = $window->Frame->pack(); my $empty2 = $clean2->Label(-text=>"")->pack(); $window->Label(-text=>'Celsius Fahrenheit Kelvin', -font=>'courierb 10 bold' )->pack(); my $ausgabe = $window->Text(-width=>60,-height=>10,-borderwidth=> '0m', -cursor=> 'left_side',-background=> 'white',-font=>'courierb 12', -foreground=> 'black')->pack(); my $bottom_frame = $window->Frame()->pack(-side=>'bottom', -pady=>10); $bottom_frame->Button( -text => 'Alles zeigen', -command => sub{ rechnen( $eingabe, $ausgabe ); return 1; } )->pack(-side=>'left'); $bottom_frame->Button( -text => "Alles löschen", -command => sub{ loeschen($ausgabe); return 1; } )->pack(-side=>'left'); $bottom_frame->Button( -text => "Beenden", -command=> sub {exit 0})->pack(-side=>'left'); $window->MainLoop(); =head1 SUBS =head2 rechnen( $eingabe, $ausgabe ) TODO: Beschr. =cut sub rechnen { my $eingabe = shift or die('Missing eingabe'); my $ausgabe = shift or die('Missing ausgabe'); my $anfang = $eingabe->Contents(); my $k = (($anfang * 9) /5 ) +32; my $f = $anfang + 273.15; $ausgabe->Contents("Fahrenheit: $k\nKelvin: $f"); } =head2 loeschen( $ausgabe ) TODO: Beschr. =cut sub loeschen { my $ausgabe = shift or die('Missing ausgabe'); $ausgabe->Contents(''); }