Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/Tk question, how to clear a text window 1

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
I have the following program:

#! C;\perl\bin\perl -w
use Tk;
$mw = MainWindow->new;
# Create necessary widgets
$f = $mw->Frame->pack;
$mw->Menubutton(-text => "Menubutton",
-menuitems => [[ 'command' => "IPconfig", -command => \&ipconfig],
[ 'command' => "Item 2"],
"-",
[ 'command' => "Item 3"],
[ 'command' => "Item 4"]])->pack;
$f->Button(-text => "Ipconfig", -command => \&ipconfig)->
pack;
$f->Button(-text => "netstat", -command => \&netstat)->
pack;
$f->Button (-text => "Exit", -command => sub {exit})->pack;
$t = $mw->Scrolled("Text")->pack;


MainLoop;

# load_file checks to see what the filename is and loads it if possible
sub ipconfig {
my @array1 = `ipconfig /all`;
foreach (@array1) {
print $t->insert("end", $_);
}
}
sub netstat {
my @array1 = `netstat -rn`;
foreach (@array1) {
print $t->insert("end", $_);
}
}

I want to add a button to clear the text window after a command is run.

Anyone know the subroutine to do that?

Thanks
 
Just add the lines in red.
Code:
#! C;\perl\bin\perl -w
use Tk;
$mw = MainWindow->new;
# Create necessary widgets
$f = $mw->Frame->pack;
$mw->Menubutton(-text => "Menubutton",
                         -menuitems => [[ 'command' => "IPconfig", -command => \&ipconfig],
                                        [ 'command' => "Item 2"],
                                        "-",
                                        [ 'command' => "Item 3"],
                                        [ 'command' => "Item 4"]])->pack;
$f->Button(-text => "Ipconfig", -command => \&ipconfig)->pack;
$f->Button(-text => "netstat", -command => \&netstat)->pack;

$f->Button(-text => "clear", -command => \&clear)->pack;
Code:
$f->Button (-text => "Exit", -command => sub {exit})->pack;
$t = $mw->Scrolled("Text")->pack;


MainLoop;

# load_file checks to see what the filename is and loads it if possible
sub ipconfig {
    my @array1 = `ipconfig /all`;
    foreach  (@array1) {
        print $t->insert("end", $_);
    }
}
sub netstat {
    my @array1 = `netstat -rn`;
    foreach  (@array1) {
        print $t->insert("end", $_);
    }
}
Code:
sub clear {
    $t->delete('0.0', 'end');
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top