Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by tptass (Sexton)
on Aug 11, 2008 at 21:16 UTC ( [id://703749]=note: print w/replies, xml ) Need Help??


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"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-28 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found