$detailLog->insert ('end', $_);
# or $detailLog->insert ('end', $string);
Then,
$detailLog->delete("1.0", 'end');
will work...there may be some apparently minor looking syntax error in your code that is causing problems.
Update: A simple text window with "clearing the text" button is shown below. A couple of other Tk options are also demo'ed. I use 'ROText' instead of 'Text' to show that this is "Read Only". Try it!
This "enable" and "disable" stuff will usually be ok, but there will be a short interval of time where the user can modify the displayed window.
I have one application where I just don't care whether or not the user modifies the text window and I don't use ROText. I'm not reading that result and modifying the database. The user can add notes, and formatting characters before doing a "copy and paste" to another application. Fine with me!
Anyway, what is the problem with $detail_log->delete("1.0", 'end');?
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::Frame; #optional - may be needed for an .exe
use Tk::ROText; #optional - may be needed for an .exe
my $mw = MainWindow->new;
my $f_menu_dialog = $mw->Frame()->pack(-side=>'top',-fill=>'x');
$f_menu_dialog->Button( -text =>"Clear All text",
-command => \&Clear_all_text,
)->pack(-side=>'left');
my $f_text = $mw->Frame( -relief => 'groove',
-borderwidth => '4',
)->pack
( -expand => 1,
-side => 'top',
-fill => 'both',
);
my $detail_log = $f_text->Scrolled('ROText',
-scrollbars => 'e')->pack;
foreach ("blah\n", "more blah\n", "yet more blah\n")
{
$detail_log -> insert('end', $_);
}
MainLoop();
sub Clear_all_text
{
$detail_log->delete("1.0", 'end');
}
|