Skip to content

Commit 7b2ae55

Browse files
committed
Add Perl code using Tkx
1 parent 165a554 commit 7b2ae55

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

text_counter_tkx.pl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use Tkx;
2+
use strict;
3+
use warnings;
4+
5+
my $app = Tkx::widget->new(".");
6+
7+
$app->g_wm_title("Text Counter Application using Tkinter");
8+
9+
sub calculate_text_count {
10+
my $text_content = $text_area.get("1.0", "end-1c");
11+
my $chars = length($text_content); #
12+
my $words = scalar(split(/\s+/, $text_content));
13+
my $lines = scalar(split(/\n/, textcontent));
14+
$text_area->configure(-text => "Characters: $chars\nWords: $words\nLines: $lines");
15+
}
16+
17+
my $text_area = $app->new_tk__scrolled("Text", -wrap => "word", -width => 40, -height => 10);
18+
$text_area->g_pack();
19+
20+
my $update_text_button = $app->new_tk__button(-text => "Calculate Text Count", -command => \&calculate_text_count);
21+
$update_text_button->g_pack();
22+
23+
my $result_label = $app->new_tk__label(-text => "Characters: 0\nWords: 0\nLines: 0");
24+
$result_label->g_pack();
25+
26+
Tkx::MainLoop();

0 commit comments

Comments
 (0)