arc_of_descent has asked for the wisdom of the Perl Monks concerning the following question:
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" ); } }
edited: Sun Jan 19 00:51:36 2003 by jeffa - major edit, removed HTML markup inside code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk tagBind problem
by castaway (Parson) on Jan 18, 2003 at 18:14 UTC | |
by {NULE} (Hermit) on Jan 18, 2003 at 18:35 UTC | |
|
Re: Tk tagBind problem
by {NULE} (Hermit) on Jan 18, 2003 at 18:19 UTC | |
|
Re: Tk tagBind problem
by arc_of_descent (Hermit) on Jan 18, 2003 at 18:38 UTC |