blackadder has asked for the wisdom of the Perl Monks concerning the following question:

Brethren

This is quite simple, this Tk based form displays directory tree structure of any given drive letter. The way it works is by typing in the drive letter in the entry box at the top and the directory tree will be displayed in a box underneath, by default the script will pick drive C to start off with. This bit works fine however, when I change to another drive, an error occurs (Tk based error implying that the script did not understand the instruction “$tk{dir_tree}->delete('0.1','end');” which is part of the sub OnNewPath. And all it was meant to do is to delete what ever is displayed in the DireTree box and replace it with DirTree structre of the drive letter that was inserted in the entry box.

Any pointers or advice is highly appreciated....
require 5.006; use strict; use Tk 800.005; use Tk::TList; use Tk::Frame; use Tk::DirTree; use Tk::Scrollbar; use Tk::Adjuster; use warnings 'all'; use vars qw/%tk %dr/; $tk{mw} = MainWindow->new (-background=>'white'); $tk{mw}->geometry('700x500'); $tk{top_frame} = $tk{mw}->Frame; $tk{left_frame} = $tk{mw}->Frame; $tk{adjuster} = $tk{mw}-> Adjuster(-widget=>$tk{left_frame},-side=>'le +ft'); $dr{PATH}='c:/'; $tk{entry_box}=$tk{top_frame}->Entry(-textvariable=>\ $dr{PATH}); $tk{dir_tree}= $tk{left_frame}->Scrolled('DirTree', -height=>'0', -wid +th=>'0',-scrollbars=>'e',); $tk{entry_box}->bind('<Key-Return>', sub {OnNewPath();}); $tk{top_frame}->pack(qw/-side top -fill x/); $tk{left_frame}->pack(qw/-side left -fill y/); $tk{adjuster}->pack(qw/-side left -fill y/); $tk{entry_box}->pack(qw/-side top -fill both -expand 1/); $tk{dir_tree}->pack(qw/-side left -fill both -expand 1/); MainLoop; exit(0); sub OnNewPath{ $tk{dir_tree}->delete('0.1',''); #this little tinker doesn't work $tk{dir_tree}->chdir( $dr{PATH} );}

Replies are listed 'Best First'.
Re: Tk::DirTree question
by Courage (Parson) on Aug 02, 2002 at 11:56 UTC
    After reading documentation on Tk::DirTree and Tk::HList I found out that delete('all') should be used.
    sub OnNewPath{ $tk{dir_tree}->delete('all'); #this little tinker now work $tk{dir_tree}->chdir( $dr{PATH} );}
    I checked and your code works with that correction.

    Courage, the Cowardly Dog

      Brilliant, I am absolutely honoured with your reply….Thanks very much.

      I can’t wait to that point in time where I can begin to help and contribute to “Seekers of Perl Wisdom” just like other Perl Hotshots such as yourself.
      Tim