cormanaz has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Monks. This strikes me as a stupid question, but about an hour of searching has failed to yield the answer. I have a Tk object that contains a text widget ($_text_dirname) with some text in it. (This was generated using the Activestate GUI Builder application that comes with Komodo.)

I am trying to write a button callback that makes use of the text. What is the proper object reference I use to get the text in the widget and assign it to a variable? I have tried variations of $dir = $_text_dirname->{'text'} to no avail. Komodo debugger says there us a key called _TkValue_ with the value .text but I have been unable to get the actual text from this.

TIA.....Steve

Replies are listed 'Best First'.
Re: Tk text widget reference
by rinceWind (Monsignor) on Nov 26, 2004 at 16:55 UTC
    According to the documentation for Tk::Text, there is a method Contents, which should Query or change the entire contents of the text widget.

    Hope this helps

    --
    I'm Not Just Another Perl Hacker

Re: Tk text widget reference
by mawe (Hermit) on Nov 26, 2004 at 20:17 UTC
    Hi!

    You can also use get:

    use Tk; my $top = new MainWindow; my $t = $top->Text()->pack(); my $b = $top->Button(-text=>"OK",-command=>\&get_it)->pack(); MainLoop; sub get_it { my $text = $t->get(0.1,"end"); print "$text\n"; }

    Hope this does what you want :)
    mawe

Re: Tk text widget reference
by zentara (Cardinal) on Nov 27, 2004 at 13:52 UTC
    It would seem that you would use;
    my $text = $_text_dirname->get('1.0','end');
    but if $_text_dirname is not a global, then you may not be able to access it from anywhere.

    The other thing to look at is the SubWidget like:

    my $textwidget = $_text_dirname->Subwidget('Text');
    Or $_text_dirname may be a hash ref, with one of it's keys actually being the Text widget. Maybe try dumping $_text_dirname with Data::Dumper or YAML, and see what it actually is.

    This is a good example of why most Tk programmers prefer to write their gui's from scratch rather than deal with wrestling with code generators.


    I'm not really a human, but I play one on earth. flash japh