in reply to Grabbing Text widget's contents after MainLoop

This is close:

use Tk; use Tk::DialogBox; my $mw = new MainWindow(); my $dialog = $mw->DialogBox(-title => "Blah", -buttons => ["OK"]); my $content_window = $dialog->add("Text")->pack(); $dialog->Show(); my $content = $content_window->Contents(); $mw->destroy(); MainLoop; print $content;

Replies are listed 'Best First'.
Re^2: Grabbing Text widget's contents after MainLoop
by GrandFather (Saint) on Jul 22, 2005 at 04:57 UTC

    Close, although the empty main window is a bit naff :-)


    Perl is Huffman encoded by design.

      My original solution was sort of over kill, this one is much better and simpler:

      use Tk; use Tk::DialogBox; my $mw = new MainWindow(); my $content; my $text = $mw->Text()->pack(); my $ok = $mw->Button(-text => "OK", -command => \&grab)->pack(); MainLoop; print $content; sub grab { $content = $text->Contents(); $mw->destroy(); }

        Yep, that's pretty good! I had a hazy idea that something like that was required, but I don't know enough Tk yet to figure it out in reasonable time. I find the doucmentation for Tk a bit heavy going and diffuse at the same time.

        Thanks for a good solution.


        Perl is Huffman encoded by design.