I wanted to check if there is already an instance of Tk, to use my library that is built upon tkinter alongside with the original. The only indicator I have found is tkinter._default_root but at the same time I want to disable the support of default root. It appears to be a dilemma but following the tk.create to _tkinter_create_impl leads me to Tkpp_New C code with the form of:
/* This is used to get the application class for Tk 4.1 and up */
argv0 = (char*)PyMem_Malloc(strlen(className) + 1);
if (!argv0) {
PyErr_NoMemory();
Py_DECREF(v);
return NULL;
}
But it relies on the className and the instance of Tk
could be subclassed, so it seems unreliable to me. To be honest, I never wrote something in C, so I'm not entirely sure if this is really an option and worth to work it out.
So my question is: Is it possible to know if there is already an instance Tk
in place ?