Quote$text->Contents(?args?)
Query or change the entire contents of the text widget. If no arguments are given, the entire contents of the text widget are returned. If any arguments are given, the entire contents of the text widget are deleted and replaced by the argument list.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
=head2 clear_frame( $frame )
Entferne alle Kindelemente aus dem Frame.
Siehe L<http://www.perlmonks.org/?node_id=643687>
=cut
sub clear_frame {
my $frame = shift or die('Missing frame.');
my @children = $frame->packSlaves();
foreach my $widget ( @children ) {
$widget->packForget();
$widget->destroy();
}
return 1;
} # /clear_frame
$text->delete('1.0', 'end');
QuoteLines are numbered from 1 for consistency with other UNIX programs that use this numbering scheme. Within a line, characters are numbered from 0.
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
use Tk; $window = MainWindow->new(-width=> '0m',-title=> 'Umrechnung'); $oben = $window->Frame->pack(); $titel = $oben->Label(-text=>"Programm für die Umrechnung von Grad Celsius in Kelvin und Fahrenheit.")->pack(); $clean = $window->Frame->pack(); $empty = $clean->Label(-text=>"")->pack(); $window->Label(-text=>'Anfangswert:')->pack(); $eingabe = $window->Text(-width=>20,-height=>1,-borderwidth=> '1m',-cursor=> 'left_side',-background=> 'white',-font=>'courierb12', -foreground=> 'black')->pack(); $window->Label(-text=>'Endwert:')->pack(); $eingabe2 = $window->Text(-width=>20,-height=>1,-borderwidth=> '1m',-cursor=> 'left_side',-background=> 'white',-font=>'courierb12', -foreground=> 'black')->pack(); $clean2 = $window->Frame->pack(); $empty2 = $clean2->Label(-text=>"")->pack(); $window->Label(-text=>'Celsius Fahrenheit Kelvin', -font=>'courierb 10 bold' )->pack(); $ausgabe = $window->Text(-width=>60,-height=>10,-borderwidth=> '0m',-cursor=> 'left_side',-background=> 'white',-font=>'courierb 12', -foreground=> 'black')->pack(); $bottom_frame = $window->Frame()->pack(-side=>'bottom', -pady=>10); $bottom_frame->Button( -text=>'Alles zeigen', -command=>\&rechnen)->pack(-side=>'left'); $bottom_frame->Button( -text => "Alles löschen", -command=>\&loeschen)->pack(-side=>'left'); $bottom_frame->Button( -text => "Beenden", -command=> sub {exit 0})->pack(-side=>'left'); MainLoop; sub rechnen { my $anfang = $eingabe->Contents; my $k = (($anfang * 9) /5 ) +32; my $f = $anfang + 273.15; $ausgabe->Contents("Fahrenheit: $k\nKelvin: $f"); } sub loeschen { $ausgabe->Contents(''); }
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 75 76 77 78 79 80 81
#!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(''); }