Hello people,

I'm facing a problem with perl and Tk.
I'm trying to code an explorer like interface for manipulating
my bookmark collection

I've submitted a part of my code (readable I hope!)
After a particular folder is double-clicked, I display the corresponding child folders.
Initially, I disply the root folder which has a hover effect using the tagBind method.
On Double-clicking the root folder, dclick is invoked. I've hard-coded the child folders right now.
For each child folder printed, I create a tag of the same name,
and to that tag I associate an event using the tagBind method

The problem I'm facing is that when the child folders are displayed, the hover effect is getting
applied for only one link, irrespective of which child link I move the mouse over.
And it's driving me absolutely crazy.
I've been with stuck with this, for more that a month now!

The code below should run on any computer having perl and Tk.
And i would seriously appreciate any help I can get!

#!/usr/bin/perl -w use strict; use Tk; use Tk::ROText; my $mw; # Main Window my $fview; # Text box (Read only) # Functions sub hover($$); sub dclick($); # Create Main Window and textbox $mw = new MainWindow; $fview = $mw->Scrolled( 'ROText', -scrollbars => "oe", -cursor => "hand2" ); $fview->pack; # Print "Root" Folder $fview->insert('end', "\n"); $fview->insert('end', "Root" , "Root"); $fview->insert("Root.last", "\n", "Root_newline"); # Hover over $fview->tagBind("Root", "<Enter>" => sub { hover("Root", 1); }); # Hover out $fview->tagBind("Root", "<Leave>" => sub { hover("Root", 0); }); # Double click $fview->tagBind("Root", "<Double-Button-1>" => sub { dclick("Root"); }); # Wait For Christmas! MainLoop; # make folder hot! sub hover($$) { my $tag = shift; my $do = shift; if ($do == 1) { $fview->tagConfigure($tag, -foreground => "red" ); } elsif ($do == 0) { $fview->tagConfigure($tag, -foreground => "black" ); } } # expand folder sub dclick($) { my $tag = shift; my @folders; my $fullpath; @folders = ( "Linux", "Mail", "Perl" ); foreach my $folder (@folders) { $fullpath = "/$folder"; # Hover over $fview->tagBind($fullpath, "<Enter>" => sub { hover($fullpath, 1); }); # Hover out $fview->tagBind($fullpath, "<Leave>" => sub { hover($fullpath, 0); }); # Diplay the folder link $fview->insert( 'Root_newline.last', $folder, $fullpath ); $fview->insert( $fullpath.".last", "\n", $fullpath."_newline" ); } }

Thanx!

--
arc_of_descent

edited: Sun Jan 19 00:51:36 2003 by jeffa - major edit, removed HTML markup inside code


In reply to Tk tagBind problem by arc_of_descent

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.