#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Tree; my($icon)=<<'END'; /* XPM */ static char * junk_xpm[] = { "10 10 6 1", " c #000000", ". c #FFFFFF", "X c #B129F8", "o c #F869A6", "O c #00FF00", "+ c #1429F8", " X..oo.+. ", " .X....+. ", " ..X...+. ", " o..X.... ", " oo..X... ", " .oo..X.. ", " ......X. ", " .+.....X ", " .+..oo.. ", " .+...oo. "}; END my $mw = MainWindow->new(-title=> 'Tree'); my $tree = $mw->Scrolled('Tree',-header=>'1',-scrollbars=>'osoe',- itemtype=>'imagetext',-separator => '|')->pack; $tree->add('hi',-text=>"hi",-bitmap=>'questhead'); $tree->indicatorCreate('hi'); $tree->setmode('hi','close'); $tree->add('hi|there',-text=>"hi there",-image=>$mw->Pixmap(-data=>$icon)); $tree->indicatorCreate('hi|there'); $tree->setmode('hi|there','close'); $tree->add('hi|there|a',-text=>"hi there",-image=>$mw->Pixmap(-data=>$icon)); $tree->indicatorCreate('hi|there|a'); $tree->setmode('hi|there|a','close'); $tree->add('hi|there|a|c',-text=>"hi there",-image=>$mw->Pixmap(-data=>$icon)); $tree->add('hi|there|b',-text=>"hi there",-image=>$mw->Pixmap(-data=>$icon)); $tree->bind("" => \&show_pos); MainLoop; sub show_pos { my ($x, $y) = $mw->pointerxy; print "$x $y\t"; my $s = $tree->nearest($y - $tree->rooty); print "$s\n"; $tree->selectionClear(); $tree->selectionSet($s); #pop a dialogbox here and get new text $tree->itemConfigure($s,0,-text=>'foobar'); }