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!

Help with Perl Tk

Status
Not open for further replies.

gammaman64

Programmer
Apr 28, 2007
9
US
I am very new to Perl and I am trying to get data that was capurted with a Dialog Widget, to display the searched results out in a Label Widget. Iam having some difficulty, any help would be greatly appriciated.


sub check {
my $check = $mw->DialogBox (
-background => 'red',
-title => 'Type the file you wish to check',
-buttons => [ 'OK', 'Cancel' ],
-default_button => 'OK',
);

my $txt;
my $entry = $check->Entry (
-textvariable => \$txt,
)->pack;




my $clicked = $check->Show();

return unless $clicked eq 'OK';

** I want the Label widget to automaitcally execute
upon the user clicking OK;





foreach $txt (@ARGV){
**** I want all of this to be displayed in a Label Widget.
print ("Checking $txt:");

if (-f $txt){
print ("The file $txt is:");
print ("readable")if(-r $txt);
print ("writable")if(-w $txt);
print ("executable") if (-x $txt);


}

elsif (-d $txt){
print ("$txt is a directory");
while ($txt)
{
(how many files are in the directory).
my $count +=1;
}




}
}
}

Thanks again to anyone who helps.
 
You want all that displayed in a Label?

It would probably be better to display it in a scrolled text widget (maybe a read-only one):

Code:
use Tk::ROText; # read-only text

# somewhere on your mainwindow...
my $output = $mw->Scrolled ('ROText',
   -scrollbars => 'e',
   -foreground => '#000000',
   -background => '#FFFFFF',
   -width      => 30,
   -height     => 10,
)->pack;

# and then instead of your print statements, do
$output->insert ('end',"Something new to show here\n");

If you insist on using a Label widget, have your Label use a -textvariable, then simply update that variable.

-------------
Cuvou.com | The NEW Kirsle.net
 
Something else that might be of interest:

If you have a lot of print() statements, it might be easier to actually bind STDOUT and STDERR to your text widget:

Here's a snippit from one of my programs
Code:
	# Create the debug window's text viewer.
	$dbgtext = $dbgTop->Scrolled ('ROText',
		-scrollbars => 'e',
		-foreground => '#000000',
		-background => '#FFFFFF',
		-wrap       => 'word',
		-font       => [
			-family => 'Courier New',
			-size   => 10,
		],
	)->pack (-fill => 'both', -expand => 1);

	my $realtext = $dbgtext->Subwidget ('rotext');
	tie *STDOUT, ref $realtext, $realtext;
	tie *STDERR, ref $realtext, $realtext;

So now, everything print()ed or warn()ed gets sent right to your text widget instead of to the console, meaning your code can continue to print stuff instead of having to change it.

On another note: don't let your text widget get destroyed if you bind STDOUT to it, otherwise your script will crash next time something tries to print.

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

Part and Inventory Search

Sponsor

Back
Top