This is just a simple demo of how to embed an xterm into a Tk application. This one puts it into a canvas, which opens the possibilities of using various backgrounds. I got the idea from a posting on the Tk::Zinc maillist by Christophe Mertz.
#!/usr/bin/perl -w use strict; use Tk; # Idea ripped from a script by Christophe Mertz of the # Tk::Zinc module, to work with a plain canvas. # The Zinc module has much more flexibility in how # you can hide windows. I had to mask the xterm with a # toplevel to hide it in the plain old canvas. # my $mw = MainWindow->new(); my $canv = $mw->Canvas(-bg => 'lightsteelblue', -relief => 'sunken', -width => 550, -height => 350)->pack(-expand => 1, -fill => 'both'); my $xtermWidth = 400; my $xtermHeight = 300; ## this Frame is needed for including the xterm in Tk::Canvas my $xtermContainer = $canv->Frame(-container => 1); my $xtid = $xtermContainer->id(); # converting the id from HEX to decimal as xterm requires a decimal Id + my ($xtId) = sprintf hex $xtid; my $dcontitem = $canv->createWindow(275,175, -window => $xtermContainer, -width => $xtermWidth+100, -height => $xtermHeight, -state => 'normal'); my $label = $canv->createText( 275,10, -text => "Hide xterm", ); $canv->Tk::bind("<Button-1>", \&hideShow); my $width = $xtermWidth; my $height = $xtermHeight; $mw->Button(-text => "Exit", -command => [sub{Tk::exit}] )->pack( ); my $tl; #used to mask xterm system("xterm -into $xtId &"); MainLoop(); sub hideShow { if ($canv->itemcget($label, -text) =~ /Hide/) { $canv->itemconfigure($label, -fill => 'white', -text => "Show xterm"); $tl = $mw->Toplevel(-use=>$xtId ); } else { $canv->itemconfigure($label, -fill => 'black', -text => "Hide xterm"); $tl->withdraw; } }

Replies are listed 'Best First'.
Re: embedding xterm into a Tk app
by gri6507 (Deacon) on Jun 03, 2004 at 21:12 UTC
    what version of Xterm has the -into option? Mine simply gives me the Help screen and dies with a "bad command line option" message.
      Oops, I'm sorry I forgot to mention that. I'm not sure at what version level, -into was introduced, but it is relatively recent. I'm using xterm version 4.2.99.903(174)

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