in reply to Re: tK Scrolled Questions?
in thread tK Scrolled Questions?

I could not get the clear window code to work. Just did nothing. Not sure what I'm doing wrong. I called from a function when a button is pressed. $detailLog->delete("1.0", 'end'); $detailLog->update;

Replies are listed 'Best First'.
Re^3: tK Scrolled Questions?
by Marshall (Canon) on Feb 26, 2011 at 00:12 UTC
    Interesting.. Can you show a simple version of your code?

    Maybe there is something amiss in the button callback? I mean if you are doing something like this:

    $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'); }