将外部应用程序嵌入框架 Tkinter

问题描述

我正在尝试将外部嵌入到 LINUX 上的 tkinter 框架中。

我已经为 Windows10 实现了一个解决方案,但我无法在 Linux 上使用 win32gui :

import subprocess
from subprocess import Popen,CREATE_NEW_CONSOLE
import pygetwindow as gw
import win32gui
import regex as re
import time
from tkinter import *


def my_proc():
    file = "Notepad.exe"
    proc = subprocess.Popen(["%s" % file])

    time.sleep(1)  # make sure the window has been started and available to find.
    pid = gw.getwindowsWithTitle('Sans titre\xa0- Bloc-notes')  # getting the hwnd window

    hwnd = re.findall(r'\d+',str(pid))
    print(hwnd)
    x = 0  # widget is the target tkinter frame
    y = 0
    width = 800
    height = 500

    stream_id = frame.winfo_id()

    win32gui.SetParent(int(hwnd[-1]),int(stream_id))
    win32gui.MoveWindow(int(hwnd[-1]),int(x),int(y),int(width),int(height),1)  # trying to move the window to the widget geometry



root = Tk()
root.geometry("1000x1000")
root.title("Coucou")

frame = Frame(root,width=800,height=800,bg="red")
frame.pack()

root.after(100,my_proc)
root.mainloop()

我试过用 xdotool 调用 Popen : xdotool windowreparent [source_window] destination_window 我的来源就消失了。你有什么想法吗?也许使用另一个 Windows 管理器?

干杯

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)