After some digging, I figured it out. I was deleting a button from the Text widget, as you'd delete text, but that destroys the button completely, so I got an error the next time I tried to re-insert it. It was still in my hash of buttons, though, which made me thing the button still exists. Took me a while to debug my sample code until I made it do what I want :)

If anyone's interested, I'm attaching my sample code. Now on to changing the original to behave the same way...

use strict; use Tk; my $mw = MainWindow->new(); my $input_frame = $mw->Frame() ->pack(-expand => 1, -fill => 'both'); my $input = $input_frame->Scrolled('Text') ->pack(-expand => 1, -fill => 'both'); $input->tagConfigure("invisible", -elide => 'true'); my %buttons; for (my $i = 1; $i < 20; $i++) { if ($i % 5 == 0) { # Create both buttons $buttons{"minus_$i"} = $input->Button(-image => $mw->Getimage('min +us'), -command => [\&hide,$i]); $buttons{"plus_$i"} = $input->Button(-image => $mw->Getimage('plus +'), -command => [\&reveal,$i]); # Insert only the minus button $input->windowCreate('end',-window => $buttons{"minus_$i"}); } $input->insert('end',"abcdefghijkl$i\n"); } MainLoop(); sub hide { my ($index) = @_; my $from = $index + 1; my $to = $index + 5; $input->tagAdd("invisible","$from.0","$to.0"); switch_button($index,'plus','minus'); return; } sub reveal { my ($index) = @_; my $from = $index + 1; my $to = $index + 5; $input->tagRemove("invisible","$from.0","$to.0"); switch_button($index, 'minus', 'plus'); return; } sub switch_button { my ($j, $new_sign, $old_sign) = @_; $input->delete("$j.0"); if ($old_sign eq 'plus') { $buttons{"plus_$j"} = $input->Button(-image => $mw->Getimage('plus +'), -command => [\&reveal,$j]); } else { $buttons{"minus_$j"} = $input->Button(-image => $mw->Getimage('min +us'), -command => [\&hide,$j]); } $input->windowCreate("$j.0",-window => $buttons{"${new_sign}_$j"}) +; return; }

EDIT: I just checked out the code in your other reply, and though I think that for now I'll stay with my version, I definitely learned a couple of new things from it. Thanks!


In reply to Re^4: Editable tree in Tk by anna_black
in thread Editable tree in Tk by anna_black

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.