Create a scrolled Text widget : Text « GUI « Perl






Create a scrolled Text widget

 

#!/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.Bind mouse double click action to a Text control
2.Call Text insert function to add text to a Text control
3.Insert text to a Text control (TextField)
4.Set width and height of a Text
5.Use the Scrolled to control the scroll of a Text Entry
6.Change text in a Text (TextField) in radio button and checkbox button action
7.Configure a Text Widget
8.Entry(text field): Set highlightthickness
9.Entry(text field): set font
10.Fill the Entry (text field): textvariable
11.Get text input in a single line Text Box
12.Insert bold text to a Text widget
13.Insert text string to a Text Widget
14.Mark text in a Scrolled Text Widget
15.Auto-scroll entry (text field)
16.Single-Line Text Entry