2

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.

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.

4
  • There's tons of google results for "tkinter teminal", what is it about those that isn't meeting your needs? Commented Apr 13, 2017 at 20:42
  • Oh wait, do you mean another GUI? Then no, there is no way to embed another GUI into a tkinter program. Commented Apr 13, 2017 at 20:44
  • Yes..that's what I meant. Is there another way to do it? Perhaps using C rather than python? Commented Apr 13, 2017 at 20:46
  • Not that I know of. A quick google suggests you can control the spotify program via the command line or dbus. You will have to make your own buttons in tkinter and have them send commands to spotify. Commented Apr 13, 2017 at 20:50

1 Answer 1

4

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

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

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.

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.