Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does Tk FileSelect() work?

Status
Not open for further replies.

gammaman64

Programmer
Apr 28, 2007
9
US
I want to be able to store the click from the selected file on the OpenFile Dialog Box so that I can open another Dialog Box which will obviously take user input. I need this input be searhed for or "parsed", obviously with a matching pattern, and I would like to have the results, written out to a file. Here is the code thus far.

sub parse{
my $file = $mw->getOpenFile(
-title=>"Click the file or directory that you wish to search",
-command=>**can I use FileSelect here*** ;
(I need the click to be stored and to execute the Dialog Box Below).

}


my $search = $mw->DialogBox (
-background => 'cyan',
-title => 'Enter the word or phrase you wish to search for',
-buttons => [ 'OK', 'Cancel' ],
-default_button => 'OK',
);
(After words are typed and Ok is clicked I need the below to parse the selected file, and write the result to a file).
my $typed;
my $type_search = $search->Entry (
-textvariable => \$typed,
)->pack;




my $click = $search->Show();

return unless $click eq 'OK';

I know a lot of this code is wrong; I personally happen to be proficient in Java and C++ and I am now trying to tackle Perl fundamentals, to build better crudentials.
 
On that link I sent you on that other topic you posted, there was some example code if you'd have actually read the content.

Here's the example for the GetOpenFile code:

Code:
#!/usr/bin/perl -w
# -*- perl -*-

#
# $Id: getopenfile.pl,v 1.1 2005/08/10 22:59:41 eserte Exp $
# Author: Slaven Rezic
#
# Copyright (C) 2000 Slaven Rezic. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Mail: eserte@cs.tu-berlin.de
# WWW:  [URL unfurl="true"]http://user.cs.tu-berlin.de/~eserte/[/URL]
#

use Tk;
use Cwd;

$top = new MainWindow;

print
    "Filename: ",
    $top->getOpenFile(-defaultextension => ".pl",
		      -filetypes        =>
		      [['Perl Scripts',     '.pl'            ],
		       ['Text Files',       ['.txt', '.text']],
		       ['C Source Files',   '.c',      'TEXT'],
		       ['GIF Files',        '.gif',          ],
		       ['GIF Files',        '',        'GIFF'],
		       ['All Files',        '*',             ],
		      ],
		      -initialdir       => Cwd::cwd(),
		      -initialfile      => "getopenfile",
		      -title            => "Your customized title",
		     ),
    "\n";

__END__

-------------
Cuvou.com | The NEW Kirsle.net
 
A quick note that the example code doesn't cover:

getOpenFile returns the file path of the file they selected, or undef if they clicked Cancel.

So, if you want your sub to continue only if they've actually selected a file, and to not continue if they clicked Cancel:

Code:
my $file = $mw->getOpenFile (...);
return unless $file;

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top