简体   繁体   English

如何使用任何 Python GUI 框架在我的应用程序中嵌入一些应用程序 window

[英]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.

相关问题 如何在 Tkinter GUI 应用程序中嵌入 SDL2 窗口? - How can I embed an SDL2 window in my Tkinter GUI application? pygtk如何在我的pygtk GUI中嵌入外部应用程序 - pygtk how to embed external application within my pygtk GUI 有没有办法添加使用Eel Python制作的GUI应用程序的徽标? - Is there any way to add a logo of the GUI application made by using Eel Python? 如何以编程方式在 python 中录制窗口/GUI 应用程序? - How do I programmatically video record a window / GUI application in python? 如何在python PyQt GUI应用程序中隐藏控制台窗口 - How to hide console window in python PyQt GUI application 如何使用 Python 在没有 GUI 的情况下直接自动化任何应用程序变量? - How to automate any application variable directly without GUI with Python? 在Python GUI中使用C应用程序 - Using C application with a Python GUI 在我的 python 应用程序中嵌入 python 作为脚本语言 - Embed python as scripting language on my python application 在我的 python 应用程序中为 GUI 使用 Tkinter 单选按钮小部件 - Using the Tkinter radio-button widget for a GUI in my python application 如何通过我自己的Python GUI应用程序创建Linux用户? - How to create linux users via my own GUI application in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM