Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Tk: Text works with TIE, Scrolled doesn't
- Stefan H.
July 14, 2005, 7:19 pm
rate this thread
my $text = $mw->Text->pack();
tie *STDOUT, ref $text, $text;
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
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
(command bound to event)
Re: Tk: Text works with TIE, Scrolled doesn't
Yes, because the Text widget (more accurately, the class Tk::Text)
implements TIE methods.
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;
@_=map"}split/!/,'/5!*2!+$]!/10+$]';use Tk;$m=tkinit;$t='just an'.
'other perl hacker';$z='createText';$c=$m->Canvas(-wi,$_,-he,25)->grid;$c->$