http://www.perlmonks.org?node_id=296652

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

Hi, guyz!

I wonder if there is any way to use Tk interface in CGI.
I cannot at the moment make a test page with smth. like
#!usr/bin/perl use Tk; $frmMain = MainWindow->new(title=>'Test'); MainLoop;

Will it work?

Replies are listed 'Best First'.
Re: Tk in CGI
by smackdab (Pilgrim) on Oct 05, 2003 at 06:02 UTC
    No, if I understand you correctly.

    Tk is a client based GUI (ie: it runs on your local PC)

    Whereas the CGI is running on the remote server...

    The web browser can only display HTML.

    BUT, if you want a netscape ONLY solution (maybe now old and broken, take a look at www.perltk.org and they might still have the link up there...)

    HTH
Re: Tk in CGI
by silent11 (Vicar) on Oct 05, 2003 at 15:53 UTC
    It's not clear to me what you are trying to accomplish, however, xul may be what you are looking for.

    -silent11
Re: Tk in CGI
by calin (Deacon) on Oct 05, 2003 at 16:04 UTC
    Well, not technically CGI, nor Perl (though you can use Perl/CGI for dynamic Tcl/Tk code generation): there is a Tcl plugin that you can install in your browser, but it doesn't seem to be maintained anymore (last release in Jan 1998).

    Update: From the web page:

    Note from Hobbs: This plugin information is old. ActiveState has reengineered the plugin. It works with MSIE 4+ and Netscape API compatible plugins across platforms (Netscape, Mozilla, Opera, ...). Binaries can be found as part of the Tcl Dev Kit starting with version 2.5 (the plugin is an unlicensed component), or the sources can be found at the Tcl plugin SF project.

    See this for newer development on the plugin. No releases, just CVS.

Re: Tk in CGI
by toma (Vicar) on Oct 05, 2003 at 17:34 UTC
    Yes, you can do what you want if you are using X-Windows.

    The trick is to set the DISPLAY environment variable in the BEGIN block, and xhost + on your X display.

    I do this when I want to run the ptkdb perl debugger, which is a Tk application, on my CGI's. I like being able to single step through my program in ptkdb and watch the browser display the results.

    I have used this on Linux and HP-UX, it probably works on many other systems, also. The X-Windows requirement makes the approach difficult to deploy widely, but the trick is useful as a programmer's tool.

    For more details see Debugging a CGI

    It should work perfectly the first time! - toma
Re: Tk in CGI
by kutsu (Priest) on Oct 05, 2003 at 15:06 UTC

    Depending on what you what to do you might want to look at HTML::Template.

    As to using a GUI interface you should be able to link to an exe file and run it over the web instead.

    Update: Thanks for clarifying that kelan

    "Pain is weakness leaving the body, I find myself in pain everyday" -me

      This will not do what you think. It won't "run it over the web", as in running the app on the webserver but presenting it on your machine. All it will do is download the executable file that you linked to, and run it on your local machine. Once the server sends you the file, it has no longer has any connection with the app (unless the app is actually written to connect back to the server in some way).

      kelan


      Perl6 Grammar Student

Re: Tk in CGI
by seaver (Pilgrim) on Oct 06, 2003 at 15:03 UTC
    Personally, I prefer Java applets.
    I was looking into using TK interactively from the web, and seeing I wanted as wide an audience as possible, it was a far better solution to go with the web technology rather than keep with old solutions like those suggested below
    Having said that, if this is really for personal use, then you should do it anyway you want.

    Cheers
    Sam