diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index e0b5f58ebbc..1316b4b882a 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -410,10 +410,19 @@ int load_tkinter_funcs(void) // Load tkinter global funcs from tkinter compiled module. // Return 0 for success, non-zero for failure. int ret = -1; - void *tkinter_lib; + void *main_program, *tkinter_lib; char *tkinter_libname; PyObject *pModule = NULL, *pSubmodule = NULL, *pString = NULL; + // Try loading from the main program namespace first + main_program = dlopen(NULL, RTLD_LAZY); + if (_func_loader(main_program) == 0) { + return 0; + } + // Clear exception triggered when we didn't find symbols above. + PyErr_Clear(); + + // Now try finding the tkinter compiled module pModule = PyImport_ImportModule(TKINTER_PKG); if (pModule == NULL) { goto exit;