tcltk-toolkit

How to embed an application in a Tk window/frame?


If it is possible to embed an application in a Tk window, would you'd please point me to the correct methods?

I'm experimenting with something like: firefox -P "ToolTest" -no-remote -new-instance -private -kiosk -url "http://127.0.0.11:8000/study" to open a browser to the local server url.

I read about the -container option for frames and the Entice paper that used TkXext that obtained the window id and reparented it. However, TkXext is not in Tclib and I'm not clear on whether or not it is still used and what platforms it'll work on.

It appears that it's easy to do so using Tkinter, at least according to this geeks for geeks example; but I'm using Tcl/Tk only.

Thank you.


Solution

  • There's two key steps:

    1. You should make the frame with -container 1 -background {}. That prepares Tk to handle another application doing things with it and disables drawing the background.

    2. You get the XID of the frame with winfo id $theFrame and get the other program to use that as its primary drawing surface. The XID will be the ID of a Window at the C level.

      If this is Tk, you do this with the -use $id option to a toplevel at creation time (an argument to wish when you launch it for .). Other applications have their own mechanisms for this; consult their documentation (or find a suitable Stack Overflow answer).

    Note that on Windows and macOS, you're unlikely to make this work except between two instances of Tk. They do drawing surface IDs in a different way.