I work a lot on Pure Data, an app written in Tcl/Tk and C. I'd like to be able to make a python API for plugins for modifying the Tcl/Tk GUI. To do this, it seems that I would need to be able to pas开发者_如何学JAVAs the running Tk instance to python, then have Tkinter use that Tcl/Tk instance for its commands. So something like:
root = Tk(pid_of_running_app)
Take a look at the send command, you can do exactly that (to Tk applications, not plain Tcl applications). I do this all the time from my Emacs (connect to running Tk applications).
Tcl/Tk won't let you enslave another process, however using the send
command, you can easily send over any commands you want to. Just find the "name" of the other interpreter by using [winfo interps]
(note: the name of your Tk application can be gotten/set by [tk appname]
. At which point, any command you want to have executed in the other interpreter would be sent over by evaluating
send $other_app tk_dialog . "Sample Dialog" "See, it's this easy." "" 0 Ok
The options are to use Tk's built-in send
infrastructure (as Trey mentions) or to use the comm package from Tcllib. It should be possible to talk the comm protocol directly from Python, but I've never looked into the details so you might as well lead the way.
You could use sockets to communicate between the 2 apps.
精彩评论