Dear Monks,

I have been working on a code for getting some information from the user using GUI and also generating a text file, which I need to manipulate later. What I want to do is for the user to enter the file at the file entry location. What I am looking for is how to add a button at the side of the file name entry location, so that the user can either enter the location of the file or use the button to open a file dialog box. Once the user clicks and opens the dialog box to enter the file information, I want the user to also be able to see the file location in the entry text location for the file entry. Could you kindly help me with this.

#!/usr/local/bin/perl use Tk; #Global Variables my $bins = 10; my $process = "180nm"; # Main Window my $mw = new MainWindow; #GUI Building Area: User specifies file location my $frm_name = $mw -> Frame(); my $lab = $frm_name -> Label(-text=>"File Name:"); my $ent = $frm_name -> Entry(); #Number of bins my $scl = $mw -> Scale(-label=>"Number of bins :", -orient=>'h', -digit=>1, -from=>10, -to=>100, -variable=>\$bins, -tickinterval=>25); #Select the process my $frm_process = $mw -> Frame(); my $lbl_process = $frm_process -> Label(-text=>"Process "); my $rdb_40 = $frm_process -> Radiobutton(-text=>"40nm:GF", -value=>"40nm", -variable=>\$process); my $rdb_65 = $frm_process -> Radiobutton(-text=>"65nm:GF", -value=>"65nm",-variable=>\$process); my $rdb_140 = $frm_process -> Radiobutton(-text=>"140nm:NXP", -value=>"140nm", -variable=>\$process); my $rdb_180 = $frm_process -> Radiobutton(-text=>"180nm:GF", -value=>"180nm",-variable=>\$process); my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button); #Text Area my $textarea = $mw -> Frame(); my $txt = $textarea -> Text(-width=>40, -height=>10); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $t +xt]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $t +xt]); $txt -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]); #Geometry Management $lab -> grid(-row=>1,-column=>1); $ent -> grid(-row=>1,-column=>2); $scl -> grid(-row=>2,-column=>1, -ipadx =>100); $frm_name -> grid(-row=>1,-column=>1,-columnspan=>2); $lbl_process -> grid(-row=>1,-column=>1); $rdb_40 -> grid(-row=>1,-column=>2); $rdb_65 -> grid(-row=>1,-column=>3); $rdb_140 -> grid(-row=>1,-column=>4); $rdb_180 -> grid(-row=>1,-column=>5); $frm_process -> grid(-row=>3,-column=>1,-columnspan=>2); $but -> grid(-row=>4,-column=>1,-columnspan=>2); $txt -> grid(-row=>1,-column=>1); $srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns"); $srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew"); $textarea -> grid(-row=>5,-column=>1,-columnspan=>2); MainLoop; ## Functions #This function will be executed when the button is pushed sub push_button { my $name = $ent -> get(); open(my $in0, '>', 'input.txt') or die "Cannot open input.txt file: $!. You might need to run the +script from a location where you have write access"; print $in0 $name, "\n"; print $in0 $process, "\n"; print $in0 $bins, "\n"; close $in0; $txt -> insert('end',"Process is $process. File location is $name +and selected bins is $bins.\n"); }
Here is the code I found for searching a file for open.
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; $mw->geometry("400x400+0+0"); my $menu_f = $mw->Frame()->pack(-side=>'top',-fill=>'x'); my $menu_file = $menu_f->Menubutton (-text=>'File',-tearoff=>'false') ->pack(-side=>'left'); $menu_file->command(-label=>'Open', -command=> \&get_file); #other menu buttons shown here as examples ... #$menu_file->command(-label=>'Save', # -command=> \&save_log); #$menu_file->command(-label=>'Close', # -command=> \&close_log); #$menu_file->command(-label=>'Exit',-command=>\&exit_msg); sub get_file { my @types = (["Log files", [qw/.txt .log/]], ["All files", '*'], ); my $filepath = $mw->getOpenFile(-filetypes => \@types) or return(); print "$filepath selected\n"; return($filepath); } MainLoop;
thanks, regards, Ganesh.

In reply to How to add both a text entry option for file location entry and also a file search option using file search by Ganesh Bharadwaj1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



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