Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2021-11-30 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?