Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: <STDIN> "anticipate" input?

by johnnyjohnny (Initiate)
on Aug 11, 2008 at 20:31 UTC ( [id://703746] : note . print w/replies, xml ) Need Help??

in reply to Re: <STDIN> "anticipate" input?
in thread <STDIN> "anticipate" input?

Yeah, that's kinda what I thought. Tryin' to use Perl/TK right now...

Replies are listed 'Best First'.
Re^3: <STDIN> "anticipate" input?
by tptass (Sexton) on Aug 11, 2008 at 21:16 UTC

    You are probably way on your way with this, but I figure I would give you two examples in one. The first you will see is the Tk::FileSelect, which brings up a browser window for the user to select a file from (I prefer this solutions, simply because history has shown my not to trust the user). However, if what you are trying to do is a little more complex than you can simply implement this by using Tk::Entry, which is an easier solution than using a Textbox.

    #!/usr/bin/perl -w use Tk; use Tk::FileSelect; use strict; my $mw = MainWindow->new; #Solution #1 the next two lines! my $FSref = $mw->FileSelect(-directory=>"C:/"); my $dir = $FSref->Show; #solution #2 up until MainLoop $mw->Label(-text => 'File Name: ')->pack; my $filename = $mw->Entry(-width => 50, -textvariable => "$dir"); $filename->pack; $mw->Button( -text => 'Print', -command => sub{do_print($filename)} )->pack; MainLoop; #used by solution #2, to print the output to the terminal sub do_print { my ($file) = @_; my $file_val = $file->get; print "You selected $file_val\n"; }