Is there anyway to connect Python / Tkinter to an already running Tcl / Tk application?

I work a lot on Pure Data, an application written in Tcl / Tk and C. I would like to be able to create a python API for plugins to modify the Tcl / Tk GUI. For this, it seems to me that I will need to pass the Tk executable instance to python, and then Tkinter to use this Tcl / Tk instance for its commands. So something like:

root = Tk(pid_of_running_app) 
+4
source share
3 answers

Take a look at the send command, you can do just that (for Tk applications, not simple Tcl applications). I do this all the time from my Emacs (connecting to Tk application launches).

Tcl / Tk will not allow you to enslave another process, however, using the send command, you can easily send any commands you want. Just find the β€œname” of another interpreter using [winfo interps] (note: the name of your Tk application can be obtained / set using [tk appname] . At this point, any command that you want to execute in another interpreter will be sent by evaluating

 send $other_app tk_dialog . "Sample Dialog" "See, it this easy." "" 0 Ok 
+5
source

As options, you should use the built-in send Tk infrastructure (as Trey mentions) or use the comm package from Tcllib . It should be possible to talk to the communication protocol directly with Python, but I never looked into the details so that you can also head the path.

+1
source

You can use sockets to communicate between two applications.

0
source

Source: https://habr.com/ru/post/1346992/


All Articles