在 Python GUI 中嵌入 Linux 程序?

编程入门 行业动态 更新时间:2024-10-23 22:37:11
本文介绍了在 Python GUI 中嵌入 Linux 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在为我的汽车构建一个类似于 Tesla Model S 的触摸界面,并且我想要原生支持 Spotify.我正在使用 tkinter 在 Python 中构建我的 GUI,我想知道是否有办法从所述 GUI 的预定义框架内的 GUI 内启动 linux 程序(在本例中为 Spotify).我想我认为这就像网页中的 iframe.

I'm building a touch interface for my car similar to the Tesla Model S and I want to support Spotify natively. I'm building my GUI in Python using tkinter and I'm wondering if there is a way to launch a linux program (in this case Spotify) from within a GUI within a pre-defined frame of said GUI. I guess I'm thinking of this like an iframe in a webpage.

我知道这可能不是最好的方法,但我的车 99% 的时间都处于离线状态,所以我需要支持离线流媒体,我可以从 Spotify 应用程序中做到这一点,而不是经常使用他们的网络 API.

I know this probably isn't the best way to do it, but my car will be offline 99% of the time, so I need to support offline streaming, which I can do from the Spotify application and not so much using their web API.

推荐答案

Tkinter 能够嵌入其他基于 X11 的应用程序,但前提是 Windows 支持嵌入自身.

Tkinter has the ability to embed other X11-based applications, but only if the windows supports embedding itself.

诀窍是获取 tkinter 小部件的 X 窗口 ID,然后让其他程序写入该窗口 ID.

The trick is to get the X window id of a tkinter widget, and then letting the other program write to that window id.

据我所知,只有少数程序可以实现这一点.xterm 就是其中之一.我想我过去也用过 mplayer.

As far as I know, there's only a handful of programs that make this possible. xterm is one. I think I've used mplayer in the past as well.

这是一个使用 xterm 的非常简单的例子:

Here's a very simple example using xterm:

import tkinter as tk
import subprocess

root = tk.Tk()
root.geometry("400x400")

label = tk.Label(root, text="Example of xterm embedded in frame")
xterm_frame = tk.Frame(root)

label.pack(side="top", fill="x")
xterm_frame.pack(fill="both", expand=True, padx=20, pady=20)

xterm_frame_id = xterm_frame.winfo_id()
subprocess.call("xterm -into %d &" % xterm_frame_id, shell=True)

root.mainloop()

这篇关于在 Python GUI 中嵌入 Linux 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:46:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390744.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   Python   GUI   Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!