in reply to Re^2: <STDIN> "anticipate" input?
in thread <STDIN> "anticipate" input?
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"; }
|
|---|