Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Tk DirSelect Buttons

by Anonymous Monk
on Apr 19, 2018 at 14:41 UTC ( [id://1213170]=note: print w/replies, xml ) Need Help??


in reply to Re: Tk DirSelect Buttons
in thread Tk DirSelect Buttons

Thank you. You were right $dir does give the value of the selected directory when OK is used and nothing when Cancel is used!
I have been using chooseDirectory but the problem is that I cannot change its size and want it to be bigger.

Replies are listed 'Best First'.
Re^3: Tk DirSelect Buttons
by zentara (Archbishop) on Apr 19, 2018 at 15:04 UTC
    the problem is that I cannot change its size and want it to be bigger

    Why don't you try a different widget? Look at this example, it allows you to make the window and font as big as you want. Tk://DirTree

    #!/usr/bin/perl use warnings; use strict; use Tk; require Tk::DirTree; require Tk::Adjuster; require Tk::TList; # an example that has been floating around the monastery for years # The initial directory my $initial_dir = '/'; # The main window... my $main = new MainWindow( -title => 'Exploreeeeeer :o)' ); # A frame for the tree, adjuster and tlist my $tree_adj_tablist = $main->Frame(); $tree_adj_tablist->pack( -expand => 'yes', -fill => 'both', -side => 'top' ); # A scrolled directory tree my $tree = $tree_adj_tablist->Scrolled( 'DirTree', -width => 155, -height => 55, -scrollbars => 'osoe', -background => 'White', -selectmode => 'single', -selectbackground => 'DarkBlue', -selectforeground => 'White', -showhidden => 1, -directory => $initial_dir ); $tree->pack( -expand => 'yes', -fill => 'both', -padx => 2, -pady => 2, -side => 'left' ); # An adjuster my $adjuster = $tree_adj_tablist->Adjuster( -widget => $tree, -side => 'left' ); $adjuster->pack( -side => 'left', -fill => 'y' ); # A scrolled tab_list widget my $tab_list = $tree_adj_tablist->Scrolled( 'TList', -background => 'White', -orient => 'vertical', -selectmode => 'extended', -scrollbars => 'os' ); $tab_list->pack( -expand => 'yes', -fill => 'both', -padx => 2, -pady => 2, -side => 'right' ); # A Quit button (will be suppressed???...) my $quit = $main->Button( -text => 'Quit', -underline => 0, -width => 6, -command => sub { exit } ); $quit->pack( -side => 'right', -padx => 10, -pady => 10 ); # Configuring tree and tab_list widgets... $tree->configure( -browsecmd => sub { list_dir( $tab_list, @_ ); } ); # We list the content of the initial dir inside the tab_list list_dir( $tab_list, $initial_dir ); MainLoop(); #--------------------------------------------------------------------- +------- # Displays Dirs and files in TList widget sub list_dir { my ( $tab_list, $path ) = @_; # Erase the TList content $tab_list->delete( 0, 'end' ); opendir MY_DIR, $path or return; foreach my $file ( sort readdir(MY_DIR) ) { # Do not display '.' and '..' next if ( $file eq '.' or $file eq '..' ); # Insert the files in the TList $tab_list->insert( 'end', -text => $file ); } closedir MY_DIR; }

    I'm not really a human, but I play one on earth. ..... an animated JAPH
      Thank you.
      I have run this and can see that I can add more buttons and no doubt get any directory selected.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213170]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found