Re: embed application into tk gui
- From: zentara <zentara@xxxxxxxxxxxxxx>
- Date: Fri, 22 Jul 2005 07:27:46 -0400
On 21 Jul 2005 08:22:21 -0700, "ennitao@xxxxxxxxx" <ennitao@xxxxxxxxx>
wrote:
>Cygwin has X11 libraries. Although a Unix platform on top of a Windows
>is not the same as linux, how would you do it on linux? Btw, I'm not
>using perl/tk just tk.
>
>Thanks,
>Elizabeth
On linux, you setup a "container", certain widgets like Frame, Canvas,
and Text support the container option. Once you have the container, you
get it's Xserver window id.
Now you need an app, that supports the option to use a specified
window-id. Xterm. mplayer, xv, and I'm sure there are others, support
the wid option.
Here is an example with mplayer:
http://perlmonks.org?node_id=417164
Or here is a simple xterm embed:
(You can't hide a container, except by masking over it)
#!/usr/bin/perl -w
use strict;
use Tk;
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;
}
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
.
- References:
- Re: embed application into tk gui
- From: zentara
- Re: embed application into tk gui
- From: ennitao@xxxxxxxxx
- Re: embed application into tk gui
- Prev by Date: Re: Scaling images in a Canvas
- Next by Date: Re: nonblocking system call
- Previous by thread: Re: embed application into tk gui
- Next by thread: Re: (fwd) Can't make labFrame line up the way I want
- Index(es):
Relevant Pages
|