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

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

by tptass (Sexton)
on Aug 11, 2008 at 21:16 UTC ( #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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2023-12-04 16:55 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (25 votes). Check out past polls.