Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Tk: Text works with TIE, Scrolled doesn't

Reply
Thread Tools

Tk: Text works with TIE, Scrolled doesn't

 
 
Stefan H.
Guest
Posts: n/a
 
      07-14-2005
the following code works properly, printing on Text all I print to
STDOUT

my $text = $mw->Text->pack();
tie *STDOUT, ref $text, $text;
print "prova";

but I want scrollbars, so I change to

my $text = $mw->Scrolled("Text")->pack();

at running time Perl output the following error. What's wrong??

Tk::Error: Failed to AUTOLOAD 'Tk::Frame::TIEHANDLE' at C:\Documents and
Setting
s\manfry\Desktop\perl\prova.pl line 163
Tk callback for .frame
Tk callback for .frame.ysbslice
Tk callback for .frame.ysbslice.corner
Carp::croak at C:/perl/lib/Carp.pm line 269
Tk::Widget::__ANON__ at C:/perl/site/lib/Tk/Widget.pm line 347
main::stampa_struttura at C:\Documents and
Settings\temp\Desktop\perl\prova.pl line 163
Tk callback for .button1
Tk::__ANON__ at C:/perl/site/lib/Tk.pm line 252
Tk::Button::butUp at C:/perl/site/lib/Tk/Button.pm line 111
<ButtonRelease-1>
(command bound to event)

 
Reply With Quote
 
 
 
 
lusol
Guest
Posts: n/a
 
      07-14-2005
Stefan H. <(E-Mail Removed)> wrote:
> the following code works properly, printing on Text all I print to
> STDOUT
>
> my $text = $mw->Text->pack();
> tie *STDOUT, ref $text, $text;
> print "prova";


Yes, because the Text widget (more accurately, the class Tk::Text)
implements TIE methods.

>
> but I want scrollbars, so I change to
>
> my $text = $mw->Scrolled("Text")->pack();
>
> at running time Perl output the following error. What's wrong??
>
> Tk::Error: Failed to AUTOLOAD 'Tk::Frame::TIEHANDLE' at C:\Documents and
> Setting
> s\manfry\Desktop\perl\prova.pl line 163


The Tk Scrolled() method does its magic by creating an outer Frame
widget and placing the Text widget and Scrollbar widgets inside the
Frame - and Scrolled() returns the Tk::Frame reference, not the
Tk::Text reference. Thus, the "tie *STDOUT, ref $text" statement TIEs
to the wrong class. And since Tk::Frame provides no TIE methods, you
see your error.

The trick is to use the Subwidget() method to fetch the Tk::Text
widget reference and tie() to that:

my $frog = $text->Subwidget( 'scrolled' );
tie *STDOUT, ref $frog, $text;

Steve
--
@_=map{eval"100${_}"}split/!/,'/5!*2!+$]!/10+$]';use Tk;$m=tkinit;$t='just an'.
'other perl hacker';$z='createText';$c=$m->Canvas(-wi,$_[1],-he,25)->grid;$c->$
z(@_[2,3],-te,$t,-fi,'gray50');$c->$z($_[2]-$],$_[3]-$],-te,$t);$m->bind('<En'.
'ter>',sub{$y=int(rand($m->screenheight));$m->geometry("+$y+$y")});MainLoop;
 
Reply With Quote
 
 
 
 
Stefan H.
Guest
Posts: n/a
 
      07-20-2005
On Thu, 14 Jul 2005 22:13:24 +0000 (UTC), lusol
<(E-Mail Removed)> wrote:

>The trick is to use the Subwidget() method to fetch the Tk::Text
>widget reference and tie() to that:
>
>my $frog = $text->Subwidget( 'scrolled' );
>tie *STDOUT, ref $frog, $text;


thanks Steve for the lesson. I'm a little bit frustrated because I don't
know what I'm doing but it works

I have experience on Perl but I never saw things like tie, * and ref.

Thanks again,
Stefan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrolled frame for Tkinter & Python Wrapper for Tile moustikitos@gmail.com Python 0 02-22-2007 09:55 PM
Adding fixed position content to a scrolled panel Simon Andrews Java 2 12-07-2006 04:25 PM
When I turn on my PC, it works, works, works. Problem! Fogar Computer Information 1 01-17-2006 12:57 AM
how to "save the user's place" on a vertically-scrolled page? Timo ASP .Net 4 05-08-2004 02:24 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM



Advertisments