I am a Tk novice, but I've got this little app mostly working with one weird bug. The buttons at the bottom keep disappearing when they are clicked and the window is resized smaller. I have tried packing the various elements each time, but nothing has helped.

Also if anyone has suggestions on a better way to do this I'm all ears. I have included all of the code and the first couple of chapters of the data.

Update:Sorry I can't get the ReadMore Tags to work Nevermind...
#!/usr/bin/perl # -------------------------------------------------------------------- +---------------------------------- # TaoTeChing.pl V1.00 # -------------------------------------------------------------------- +---------------------------------- # Display a Specfied or Random Chapter of the Tao Te Ching # Written by Lao-tzu # Translated by S. Mitchell # -------------------------------------------------------------------- +---------------------------------- use strict; use warnings; use constant error => -1; use constant noerror => 0; use constant false => 0; use constant true => 1; use constant MinChapter => 1; use constant MaxChapter => 81; use constant Left => -1; use constant Right => 1; $| = true; # # Modules Used # use Data::Dumper; use File::Basename; use Tk; use Tk::Adjuster; use Tk::Frame; use Tk::Text; # # Who am I? # my $MyName = (fileparse($0, '\..*'))[0]; # # Globals # my $Chapter; my $mw = new MainWindow; my $tf; my $aj; my $bf; my $OutputText; my $LeftButton; my $RightButton; # # GetChapter # # Get the Text of the Specified Chapter # # Arguments: $Chapter # # Returns: @ChapterText # sub GetChapter { my ($Chapter) = shift; my @ChapterText; my $FoundChapterHeading = false; while(<DATA>) { if(/^\Q$Chapter\E$/) { $FoundChapterHeading = true; next; } if($FoundChapterHeading) { if(/^\d+$/) { last; } else { push(@ChapterText, $_); } } } seek(DATA, 0, 0); return(@ChapterText); } # # DisplayChapter # # Display Specified Chapter # # Arguments: $Chapter # # Returns: # sub DisplayChapter { my ($Chapter) = shift; my @ChapterText = GetChapter($Chapter); my $MaxLineLength = 0; foreach(@ChapterText) { if(length($_) > $MaxLineLength) { $MaxLineLength = length($_); } } my $GeometryString = ($MaxLineLength * 8) . 'x' . (scalar(@Chapter +Text) * 20); $mw->geometry($GeometryString); $mw->title(' ' x ((($MaxLineLength - 2) / 2) + 5) . (sprintf('%2d', + $Chapter))); $OutputText->delete('1.0', 'end'); foreach my $Line (@ChapterText) { print(' ' x (($MaxLineLength - length($Line)) / 2) . $Line); } $OutputText->pack(qw/-side bottom -fill both -expand 1/); } # # ButtonHandler # # Process Button Presses # # Arguments: $ButtonType # # Returns: # sub ButtonHandler { my ($Type) = shift; $Chapter += $Type; if($Chapter < MinChapter) { $Chapter = MaxChapter; } elsif($Chapter > MaxChapter) { $Chapter = MinChapter; } DisplayChapter($Chapter); } # # Main # if($ARGV[0] and $ARGV[0] > 0 and $ARGV[0] < 82) { $Chapter = $ARGV[0]; } else { $Chapter = int(rand(81)) + 1; } $tf = $mw->Frame; # Top Frame; $aj = $mw->Adjuster(-widget => $tf, -side => 'bottom', -restore => tru +e); $bf = $mw->Frame; # Bottom Frame $OutputText = $tf->Text ( -height => '1' , -width => '1' , ); $LeftButton = $bf->Button ( -command => [ \&ButtonHandler, Left ] , -height => '1' , -text => '<' , -width => '1' , )->pack ( -side => 'left' , -fill => 'both' , -expand => true ); $RightButton = $bf->Button ( -command => [ \&ButtonHandler, Right ] , -height => '1' , -text => '>' , -width => '1' , )->pack ( -side => 'left' , -fill => 'both' , -expand => true ); tie *STDOUT, ref $OutputText, $OutputText; $tf->pack(qw/-side top -fill both -expand 1/); $aj->pack(qw/-side top -fill y/); $bf->pack(qw/-side top -fill y/); $LeftButton->pack; $RightButton->pack; DisplayChapter($Chapter); MainLoop; __DATA__ 1 The tao that can be told is not the eternal Tao The name that can be named is not the eternal Name. The unnamable is the eternally real. Naming is the origin of all particular things. Free from desire, you realize the mystery. Caught in desire, you see only the manifestations. Yet mystery and manifestations arise from the same source. This source is called darkness. Darkness within darkness. The gateway to all understanding. 2 When people see some things as beautiful, other things become ugly. When people see some things as good, other things become bad. Being and non-being create each other. Difficult and easy support each other. Long and short define each other. High and low depend on each other. Before and after follow each other. Therefore the Master acts without doing anything and teaches without saying anything. Things arise and she lets them come; things disappear and she lets them go. She has but doesn't possess, acts but doesn't expect. When her work is done, she forgets it. That is why it lasts forever. 3 . . .

In reply to Disappearing Tk buttons by NateTut

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.