| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Perl/Tk version of Tix4.1.0/demos/samples/Tree.tcl. Not quite as |
| 4 |
# nice as the Tix version: fonts and colors are different, and the |
| 5 |
# collapse/expand buttons are higlighted differently. |
| 6 |
# |
| 7 |
# Chris Dean <[email protected]> |
| 8 |
|
| 9 |
use lib ".."; |
| 10 |
|
| 11 |
use strict; |
| 12 |
use Tk; |
| 13 |
use Tk::Tree; |
| 14 |
|
| 15 |
my $top = new MainWindow( -title => "Tree" ); |
| 16 |
|
| 17 |
my $tree = $top->Scrolled( qw/Tree -separator \ -exportselection 1 |
| 18 |
-scrollbars osoe / ); |
| 19 |
$tree->pack( qw/-expand yes -fill both -padx 10 -pady 10 -side top/ ); |
| 20 |
|
| 21 |
my @directories = qw( C: C:\Dos C:\Windows C:\Windows\System ); |
| 22 |
|
| 23 |
foreach my $d (@directories) { |
| 24 |
my $text = (split( /\\/, $d ))[-1]; |
| 25 |
$tree->add( $d, -text => $text, -image => $tree->Getimage("folder") ); |
| 26 |
} |
| 27 |
|
| 28 |
$tree->configure( -command => sub { print "@_\n" } ); |
| 29 |
|
| 30 |
# The tree is fully expanded by default. |
| 31 |
$tree->autosetmode(); |
| 32 |
|
| 33 |
my $ok = $top->Button( qw/-text Ok -underline 0 -width 6/, |
| 34 |
-command => sub { exit } ); |
| 35 |
my $cancel = $top->Button( qw/-text Cancel -underline 0 -width 6/, |
| 36 |
-command => sub { exit } ); |
| 37 |
|
| 38 |
$ok->pack( qw/-side left -padx 10 -pady 10/ ); |
| 39 |
$cancel->pack( qw/-side right -padx 10 -pady 10/ ); |
| 40 |
|
| 41 |
MainLoop(); |