[英]How to embed some application window in my application using any Python GUI framework
I want some application to look like widget inside my Python application.我希望某些应用程序看起来像我的 Python 应用程序中的小部件。
That's all.就这样。 I dont need any interaction between them.
我不需要他们之间的任何互动。 I'm interested in solutions in any GUI toolkit for both windows and x windows.
我对 windows 和 x windows 的任何GUI 工具包中的解决方案感兴趣。
It would be nice to have a solution with Tkinter but it's not crucial.如果有 Tkinter 的解决方案就好了,但这并不重要。
Using GTK on X windows (ie Linux, FreeBSD, Solaris), you can use the XEMBED protocol to embed widgets using gtk.Socket
.在 X windows(即 Linux、FreeBSD、Solaris)上使用 GTK,您可以使用 XEMBED 协议使用
gtk.Socket
嵌入小部件。 Unfortunately, the application that you're launching has to explicitly support it so that you can tell it to embed itself.不幸的是,您要启动的应用程序必须明确支持它,以便您可以告诉它嵌入自己。 Some applications don't support this.
某些应用程序不支持此功能。 Notably, I can't find a way to do it with Firefox.
值得注意的是,我找不到使用 Firefox 的方法。
N.netheless, here's a sample program that will run either an X terminal or an Emacs session inside a GTK window: N.netheless,这里有一个示例程序,它将运行 X 终端或 Emacs session 在 GTK window 中:
import os
import gtk
from gtk import Socket, Button, Window, VBox, HBox
w = Window()
e = Button("Emacs")
x = Button("XTerm")
s = Socket()
v = VBox()
h = HBox()
w.add(v)
v.add(s)
h.add(e)
h.add(x)
v.pack_start(h, expand=False)
def runemacs(btn):
x.set_sensitive(False); e.set_sensitive(False)
os.spawnlp(os.P_NOWAIT, "emacs",
"emacs", "--parent-id", str(s.get_id()))
def runxterm(btn):
x.set_sensitive(False); e.set_sensitive(False)
os.spawnlp(os.P_NOWAIT, "xterm",
"xterm", "-into", str(s.get_id()))
e.connect('clicked', runemacs)
x.connect('clicked', runxterm)
w.show_all()
gtk.main()
Not enough reputation to comment on Glyphs answer.没有足够的声誉来评论 Glyphs 的答案。 To make xterm work, in addition to the comments above one needs to also add
要使 xterm 工作,除了上面的注释外,还需要添加
XTerm*allowSendEvents: True
to ~/.Xresources
.到
~/.Xresources
。 (and perhaps reload those, with xrdb -load ~/.Xresources
) (也许重新加载那些,用
xrdb -load ~/.Xresources
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.