Discussion:
[Tkinter-discuss] embedding in Tkinter
Alessandro Magni
2011-09-06 12:24:35 UTC
Permalink
Hi everybody,
I hope somebody here can give me a hand - I'm not so expert in GUI programming.
I tried - in a Tkinter program I'm writing - to embed a terminal
(linux here) in the main window - the program is a simple wiki, and I
believe it's useful to have a small terminal handy...
Optionally, I would like also to be able to let my program interact
with the terminal - at a minimum I'd like to read the current working
directory, and to set it.

I tried asking about it on stackoverflow, but without much results
(apart from some suggestions about pyGTK being the wave of the future,
of course...)

I don't know if it is really impossible - but at least I was able to
do it in the past with Perl/Tk, so maybe it can be replicated here.

The code I used then was something like:

$frame3=$mw->Frame();
$cv=$frame3->Canvas()->pack(-expand => 1, -fill => 'both');

my $xtermContainer = $cv->Frame(-container => 1); # this Frame is
needed for including the xterm in Tk::Canvas

my $xtid = $xtermContainer->id();
my ($xtId) = sprintf hex $xtid; # converting the id from HEX to
decimal as xterm requires a decimal Id

my $dcontitem = $cv->createWindow($xtermWidth/2,$xtermHeight/2,
-window => $xtermContainer,
-width => $xtermWidth,
-height => $xtermHeight,
-state => 'normal');

system("xterm -into $xtId -fn $fontname -geometry $geometry +sb -bg
black -fg white -e ./xtermjob.pl &");



(...hoping no python purist wants to shoot me in the head for showing
perl in a python mailing list :-)



I tried using a code similar to the following, but it doesnt work...

termf = Frame(root)
termf.pack(side=BOTTOM, fill=X)
id=termf.winfo_id()
os.system("xterm -into %d -e /root/.bashrc &" % id);

Does somebody here have an experience with this problem?


Thanks a lot!


alessandro
John McMonagle
2011-09-06 23:44:21 UTC
Permalink
Post by Alessandro Magni
Hi everybody,
I hope somebody here can give me a hand - I'm not so expert in GUI programming.
I tried - in a Tkinter program I'm writing - to embed a terminal
(linux here) in the main window - the program is a simple wiki, and I
believe it's useful to have a small terminal handy...
Optionally, I would like also to be able to let my program interact
with the terminal - at a minimum I'd like to read the current working
directory, and to set it.
I tried asking about it on stackoverflow, but without much results
(apart from some suggestions about pyGTK being the wave of the future,
of course...)
I don't know if it is really impossible - but at least I was able to
do it in the past with Perl/Tk, so maybe it can be replicated here.
$frame3=$mw->Frame();
$cv=$frame3->Canvas()->pack(-expand => 1, -fill => 'both');
my $xtermContainer = $cv->Frame(-container => 1); # this Frame is
needed for including the xterm in Tk::Canvas
my $xtid = $xtermContainer->id();
my ($xtId) = sprintf hex $xtid; # converting the id from HEX to
decimal as xterm requires a decimal Id
my $dcontitem = $cv->createWindow($xtermWidth/2,$xtermHeight/2,
-window => $xtermContainer,
-width => $xtermWidth,
-height => $xtermHeight,
-state => 'normal');
system("xterm -into $xtId -fn $fontname -geometry $geometry +sb -bg
black -fg white -e ./xtermjob.pl &");
(...hoping no python purist wants to shoot me in the head for showing
perl in a python mailing list :-)
I tried using a code similar to the following, but it doesnt work...
termf = Frame(root)
termf.pack(side=BOTTOM, fill=X)
id=termf.winfo_id()
os.system("xterm -into %d -e /root/.bashrc &" % id);
Does somebody here have an experience with this problem?
Thanks a lot!
I've modified your little example above with some success:

from Tkinter import *
import os

root = Tk()
termf = Frame(root, height=200, width=400)
termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 400x200 -e /root/.bashrc&' % wid)

root.mainloop()


Happy experimenting,

John
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Cameron Laird
2011-09-07 00:44:20 UTC
Permalink
Post by John McMonagle
Post by Alessandro Magni
Hi everybody,
I hope somebody here can give me a hand - I'm not so expert in GUI programming.
I tried - in a Tkinter program I'm writing - to embed a terminal
(linux here) in the main window - the program is a simple wiki, and I
believe it's useful to have a small terminal handy...
Optionally, I would like also to be able to let my program interact
with the terminal - at a minimum I'd like to read the current working
directory, and to set it.
.
.
.
Post by John McMonagle
from Tkinter import *
import os
root = Tk()
termf = Frame(root, height=200, width=400)
termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 400x200 -e /root/.bashrc&' % wid)
root.mainloop()
.
.
.
Alessandro, when you write "Optionally, I would like also to be
able to let my program interact with the terminal - at a minimum
I'd like to read the current working directory, and to set it"
and "... it doesn't work", I am unsure of your meaning. John
answered what I understand of your question about Tkinter coding
well; do you also want help communicating between the xterm's
$SHELL and the Python application, or do you have what you need
for that aspect, already?
Alessandro Magni
2011-09-07 10:11:56 UTC
Permalink
Post by John McMonagle
Post by Alessandro Magni
Hi everybody,
I hope somebody here can give me a hand - I'm not so expert in GUI programming.
I tried - in a Tkinter program I'm writing - to embed a terminal
(linux here) in the main window - the program is a simple wiki, and I
believe it's useful to have a small terminal handy...
Optionally, I would like also to be able to let my program interact
with the terminal - at a minimum I'd like to read the current working
directory, and to set it.
from Tkinter import *
import os
root = Tk()
termf = Frame(root, height=200, width=400)
termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 400x200 -e /root/.bashrc&' % wid)
root.mainloop()
. .
Post by John McMonagle
Alessandro, when you write "Optionally, I would like also to be
able to let my program interact with the terminal - at a minimum
I'd like to read the current working directory, and to set it"
and "... it doesn't work", I am unsure of your meaning. John
answered what I understand of your question about Tkinter coding
well; do you also want help communicating between the xterm's
$SHELL and the Python application, or do you have what you need
for that aspect, already?
John, Cameron,
thank you so much for your help...
I feel a bit stupid, what was happening was a problem in the launch of
xterm (I mistakenly wrote an option), Tkinter works flawlessly...

Anyway I'm glad we talked about it since the general mood on
stackoverflow was - as I said - that a) it was a very complex problem
and b) you could not hope to solve it with such a joke as Tkinter.
Serve them right! I answered them with your help, let's see if they
can do it in so few lines with pyGTK :-)

Anyway I'm still working on the interaction between the program and
the terminal: I dont know if it can be done internally by python, but
I found this program http://www.thrysoee.dk/xtermcontrol/ that could
help, I'm working on it...

thank you again


alessandro

Loading...