Prints out contents of Text widget to screen : Action « GUI « Perl






Prints out contents of Text widget to screen

 

#!/usr/bin/perl -w

use Tk;

$main = MainWindow->new();

$menubar = $main->Frame(-relief => "raised",
                        -borderwidth => 2);

$filebutton = $menubar->Menubutton(-text => "File",
                                   -underline => 0);  # F in File

$filemenu = $filebutton->Menu();

$filebutton->configure(-menu=>$filemenu);

$filemenu->command(-command => \&open_choice,
                   -label     => "Open...",
                   -underline => 0); # O in Open

$filemenu->command(-command => \&dump_choice,
                   -label     => "Print",
                   -underline => 0); # P in Print

$filemenu->command(-label => "Exit",
                   -command   => \&exit_choice,
                   -underline => 1);  # "x" in Exit

$filebutton->pack(-side=>"left");

$menubar->pack(-side=>"top", -fill=>"x");


$text = $main->Scrolled('Text',
                        -relief      => "sunken",
                        -borderwidth => 2,
                        -setgrid     => "true",
                        -scrollbars  => 'se' );
                    
$text->insert("1.0","this is a test.");

$text->pack(-side   =>"top", 
            -expand => 1,
            -fill   => 'both');

MainLoop();

sub exit_choice {
    print "You chose the Exit choice!\n";
    exit;
}

sub open_choice {
    $status->configure(-text=>"Open file.");

    print "Open file\n";
}

sub dump_choice {
    $status->configure(-text=>"Dumping text...");

    print $text->get("1.0", "end");
}

   
  








Related examples in the same category

1.Add Action Listener to Button
2.Exit an Application with 'exit' Command
3.Update entry content based on the selection in a list box