My co-workers were joking (I hope that they were joking at least) that my e-mails (which are always technical, detailed and sometimes boring) come across as no more than "blah, blah, blah, blah..." I replied that I would simplify things for them by writing a program to translate them to that literally before I sent it. Whipping up a one-liner to work on files or pipes was easy, but a Tk app that you can cut and past into was more useful (um, not that this is useful in any way).

I decided that it would be fun to write such a program and that more importantly, it might be useful to some of the folks around here that want to learn Tk. It doesn't include nearly all of the features of Tk, but it does include some that are perhaps less than obvious. It uses scrolled text windows, adjuster bars, and packing nested frames. It also shows a simple dialog box.

Anyway - I hope someone finds my waste of time useful.

#! /usr/bin/perl # Like all good Perl programmers use strict; use warnings; # Tk elements we will be using use Tk; use Tk::Adjuster; use Tk::DialogBox; use Tk::ROText; use Tk::Text; # A hash to hold all Tk widgets my $w = {}; # Main window $w->{main} = MainWindow->new(-title => 'Tk Babelizer'); # Scrolled Text widget for the input. $w->{in} = $w->{main}->Scrolled( 'Text', -width => 60, -height => 15, -wrap => 'word', -scrollbars => 'osoe' )->pack( -fill => 'both', -expand => 1 ); # An adjuster bar so the user can change the in box to out box ratio. $w->{adj} = $w->{main}->Adjuster->packAfter($w->{in}, -side => 'top'); # Frame to hold the stuff on the bottom. $w->{bottom} = $w->{main}->Frame->pack(-fill => 'both', -expand => 1); # A frame within the bottom frame to hold some buttons. $w->{buttons} = $w->{bottom}->Frame->pack( -expand => 1 ); # A button to run the babelizer process $w->{buttons}->Button( -text => 'Translate me!', -command => [ \&babelizer, $w ] )->pack( -side => 'left' ); # A button to clear the windows $w->{buttons}->Button( -text => 'Clear the windows', -command => [ \&clear_windows, $w ] )->pack( -side => 'left' ); # A button to exit $w->{buttons}->Button( -text => 'Quit', -command => [ \&quit, $w ] )->pack( -side => 'left' ); # The read-only text output (Scrolled again) $w->{out} = $w->{bottom}->Scrolled( 'ROText', -width => 60, -height => 15, -wrap => 'word', -scrollbars => 'osoe' )->pack( -fill => 'both', -expand => 1 ); # Done creating widgets, enter event loop. MainLoop; # Events # This sub runs the babelizer sub babelizer { my $w = shift; # No globals here - $w is passed to us my $text = $w->{in}->get('1.0', 'end') || ''; $text =~ s/\w+/blah/g; $w->{out}->delete('1.0', 'end'); $w->{out}->insert('1.0', $text); $w->{main}->update; } # This sub just clears the windows sub clear_windows { my $w = shift; $w->{in}->delete('1.0', 'end'); $w->{out}->delete('1.0', 'end'); $w->{main}->update; } # Pop open a confirm window to quit sub quit { my $w = shift; my $dialog = $w->{main}->DialogBox( -title => 'Confirm exit', -buttons => [ 'OK', 'Cancel' ] ); $dialog->Label( -text => 'Are you sure you want to quit?' )->pack; my $popup = $dialog->Show; if ($popup eq "OK") { exit; } }

In reply to Tk Babelizer by {NULE}

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.