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} );}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.