Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to add both a text entry option for file location entry and also a file search option using file search

by stefbv (Curate)
on Aug 01, 2016 at 15:49 UTC ( #1168931=note: print w/replies, xml ) Need Help??


in reply to How to add both a text entry option for file location entry and also a file search option using file search

This is how I would do it:

#!/usr/local/bin/perl # # Uses pack for the Label Frames so it behaves nicely on window resizi +ng # use strict; use warnings; use Tk; use Tk::widgets qw(LabFrame JFileDialog); # RadiobuttonGroup use File::Spec::Functions qw(canonpath); use File::HomeDir; # Global Variables my $bins = 10; my $process = "180nm"; my $mw = MainWindow->new; my $file_lf = $mw->LabFrame( -label => 'File Name', -labelside => 'acrosstop', -foreground => 'blue', ); $file_lf->pack( -expand => 0, -fill => 'x', ); # File my $ent = $file_lf->Entry( -width => 35, )->grid( -row => 0, -column => 0, -padx => 5, -pady => 5, ); my $file_btn = $file_lf->Button( -text => 'Select', -command => sub { get_file() }, )->grid( -row => 0, -column => 1, -padx => 5, -pady => 5, ); # Scale my $bins_lf = $mw->LabFrame( -label => 'Number of bins', -labelside => 'acrosstop', -foreground => 'blue', ); $bins_lf->pack( -expand => 0, -fill => 'x', ); # Number of bins my $scl = $bins_lf->Scale( -orient => 'h', -digit => 1, -from => 10, -to => 100, -variable => \$bins, -tickinterval => 25 )->pack( -ipadx => 100, ); my $process_lf = $mw->LabFrame( -label => 'Process', -labelside => 'acrosstop', -foreground => 'blue', ); $process_lf->pack( -expand => 0, -fill => 'x', ); # Select the process # Would be easier with RadiobuttonGroup, but I got some random failure +s... # my $process = [ "40nm:GF", "65nm:GF", "140nm:NXP", "180nm:GF" ]; # my $vprocess; # my $rgen = $process_lf->RadiobuttonGroup( # -list => $process, # -orientation => 'horizontal', # -variable => \$vprocess, # )->pack; my $frm_process = $process_lf->Frame()->pack; # just for centering the + buuton row my $rdb_40 = $frm_process->Radiobutton( -text => "40nm:GF", -value => "40nm", -variable => \$process )->pack( -side => 'left' ); my $rdb_65 = $frm_process->Radiobutton( -text => "65nm:GF", -value => "65nm", -variable => \$process )->pack( -side => 'left' ); my $rdb_140 = $frm_process->Radiobutton( -text => "140nm:NXP", -value => "140nm", -variable => \$process )->pack( -side => 'left' ); my $rdb_180 = $frm_process->Radiobutton( -text => "180nm:GF", -value => "180nm", -variable => \$process )->pack( -side => 'left' ); # Run my $run_lf = $mw->LabFrame( -label => 'Run', -labelside => 'acrosstop', -foreground => 'blue', ); $run_lf->pack( -expand => 1, -fill => 'both', ); my $but = $run_lf->Button( -text => "Go!", -command => \&push_button, )->pack; my $txt = $run_lf->Scrolled( 'Text', -width => 40, -height => 5, -wrap => 'word', -scrollbars => 'e', -background => 'white', ); $txt->pack( -expand => 1, -fill => 'both', -padx => 5, -pady => 5, ); MainLoop; # Functions sub push_button { my $name = $ent->get(); $name ||= '?'; # ... $txt->insert( 'end', "Process is $process. File location is $name and selected bins + is $bins.\n" ); } sub get_file { # JFileDialog works better on Windows XP ;) # Use getOpenFile if that's not important my $file_dlg = $mw->JFileDialog( -Title => 'File name', -Create => 0, -Path => File::HomeDir->my_documents, -FPat => '*.txt', -ShowAll => 'NO' ); my $file = $file_dlg->Show(-Horiz => 1); unless ($file) { print "cancelled...\n"; return; } $file = canonpath($file); update_file($file); return; } sub update_file { my $value = shift; $ent->delete( 0, 'end' ); $ent->insert( 0, $value ) if defined $value; return; }

I think it looks a little better... :)

Regards, Stefan.

  • Comment on Re: How to add both a text entry option for file location entry and also a file search option using file search
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2021-10-25 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?