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

Hello Monks

Searching for an easy to use TK rendering for Html I've found Tk::HyperText. I don't really understand what I'm doing wrong, but the following simple example is not working

#!/usr/bin/perl -w use strict; use warnings; use Tk; use Tk::HyperText; my $mw = MainWindow->new ( -title => 'HTML Viewer', ); my $hypertext = $mw->Scrolled ("HyperText", -scrollbars => 'e', -wrap => 'word', )->pack (-fill => 'both', -expand => 1); my $btnInsert = $mw->Button ( -text => 'insert', -command => \&insert, )->pack (-side => 'right'); MainLoop; insert(); sub insert{ # insert some HTML code $hypertext->insert ("end","<body bgcolor=\"black\" text=\"yellow\">" . "Hello, <b>world!</b></body>"); }

Thanks

Replies are listed 'Best First'.
Re: Html rendering with Tk::HyperText
by zentara (Cardinal) on Jun 15, 2014 at 22:06 UTC
    I found this usage right in the modules pod. It seems your insert should be a loadstring, and you may have to provide full html, not just fragments. Also your use of insert() after MainLoop is useless. Maybe you want it before MainLoop?

    This works:

    #!/usr/bin/perl -w use strict; use warnings; use Tk; use Tk::HyperText; my $mw = MainWindow->new ( -title => 'HTML Viewer', ); my $hypertext = $mw->Scrolled ("HyperText", -scrollbars => 'e', -wrap => 'word', )->pack (-fill => 'both', -expand => 1); my $btnInsert = $mw->Button ( -text => 'insert', -command => \&insert, )->pack (-side => 'right'); MainLoop; insert(); # this insert here will only run after # the MainLoop is done. Useless use. sub insert{ # insert some HTML code # $hypertext->insert ("end","<body bgcolor=\"black\" text=\"yellow\"> +" # . "Hello, <b>world!</b></body>"); $hypertext->loadString (qq~<html> <head> <title>Hello world!</title> </head> <body bgcolor="#0099FF"> <font size="6" family="Impact" color="#FFFFFF"> <strong>Hello, world!</strong> </font> </body> </html> ~); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Html rendering with Tk::HyperText
by wjw (Priest) on Jun 15, 2014 at 21:50 UTC

    In terms of what is it not working? I ran the script and it does exactly what you have programmed it to do as close as I can tell.

    Have you checked out the demo.pl script that the docs say is provided with the install? I have not, but it might be helpful... (see Docs for Tk::HyperText)

    In the mean time, might I suggest a quick read of How do I post a question effectively? or Thought(s) about SOP questions... just to help you help us help you a bit more efficiently.

    Hope that is helpful....

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

    A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct