I have a perl tk gui with a Help_Guide command button and a text widget, which is filled from a txt file, i am trying to add a close_help button that will clear the contents of the text widget but get this error
Tk::Error: Not a CODE reference at C:/Perl/site/lib/Tk.pm line 251. Tk callback for .frame.frame.button3 Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 251 Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm line 175 <ButtonRelease-1> (command bound to event)
This my updated code which unfortunately still does not clear the text loaded from the help button.
use warnings; use strict; use Tk; use Tk::Text ; use POSIX 'strftime'; my $DATE = strftime("Run Failures.pl for %dth %b %Y" , localtime()); my $mw = MainWindow->new; my $filename = "c:\\Temp\\perl.txt"; $mw->geometry("720x500"); $mw->title(" backupadmin "); my $main_frame = $mw->Frame()->pack(-side => 'top', -fill => 'x'); my $left_frame = $main_frame->Frame(-background => "snow2")->pack(-sid +e => 'left', -fill => 'y'); my $right_frame = $main_frame->Scrolled("Text", -scrollbars => 'se',-b +ackground => "black",-foreground => "yellow",-height => '44')->pack(- +expand => 1, -fill => 'both'); my $failures_button = $left_frame->Button(-text => " $DATE ", -command => \&runscript)->pack; my $Close_button = $left_frame->Button(-text => ' + Close ', -command => $mw => 'destroy')->pack; my $Help_button = $left_frame->Button(-text => " Help + Guide ", -command => \&load_file)->pack(-side = +> "bottom"); my $Close_help = $left_frame->Button(-text => ' Close Help ', -command => \&clear_file )->pack(-side => "bottom"); MainLoop; sub runscript { system("daily_failures.pl"); # or if it takes some time to run the script #system("daily_failures.pl &"); # runs in the background } sub load_file { open (FH, "$filename"); while (<FH>) { $right_frame->insert("end", $_); } close (FH); } sub clear_file { $right_frame->delete('1.0','end'); $right_frame->packForget; }

In reply to perl tk how to clear contents of text widget by john.tm

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.