@@ -92,6 +92,7 @@ static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK;
9292// Global vars for Tcl functions. We load these symbols from the tkinter
9393// extension module or loaded Tcl libraries at run-time.
9494static Tcl_SetVar_t TCL_SETVAR;
95+ static Tcl_SetVar2_t TCL_SETVAR2;
9596
9697static void
9798mpl_tk_blit (py::object interp_obj,const char *photo_name,
@@ -173,7 +174,15 @@ DpiSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
173174 std::string dpi =std::to_string (LOWORD (wParam));
174175
175176 Tcl_Interp* interp = (Tcl_Interp*)dwRefData;
176- TCL_SETVAR (interp, var_name.c_str (), dpi.c_str (),0 );
177+ if (TCL_SETVAR) {
178+ TCL_SETVAR (interp, var_name.c_str (), dpi.c_str (),0 );
179+ }else if (TCL_SETVAR2) {
180+ TCL_SETVAR2 (interp, var_name.c_str (),NULL , dpi.c_str (),0 );
181+ }else {
182+ // This should be prevented at import time, and therefore unreachable.
183+ // But defensively throw just in case.
184+ throw std::runtime_error (" Unable to call Tcl_SetVar or Tcl_SetVar2" );
185+ }
177186 }
178187return 0 ;
179188case WM_NCDESTROY:
@@ -246,13 +255,16 @@ bool load_tcl_tk(T lib)
246255if (auto ptr =dlsym (lib," Tcl_SetVar" )) {
247256 TCL_SETVAR = (Tcl_SetVar_t)ptr;
248257 }
258+ if (auto ptr =dlsym (lib," Tcl_SetVar2" )) {
259+ TCL_SETVAR2 = (Tcl_SetVar2_t)ptr;
260+ }
249261if (auto ptr =dlsym (lib," Tk_FindPhoto" )) {
250262 TK_FIND_PHOTO = (Tk_FindPhoto_t)ptr;
251263 }
252264if (auto ptr =dlsym (lib," Tk_PhotoPutBlock" )) {
253265 TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)ptr;
254266 }
255- return TCL_SETVAR && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
267+ return ( TCL_SETVAR || TCL_SETVAR2) && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
256268}
257269
258270#ifdef WIN32_DLL
@@ -343,8 +355,8 @@ PYBIND11_MODULE(_tkagg, m, py::mod_gil_not_used())
343355throw py::error_already_set ();
344356 }
345357
346- if (!TCL_SETVAR) {
347- throw py::import_error (" Failed to load Tcl_SetVar" );
358+ if (!( TCL_SETVAR || TCL_SETVAR2) ) {
359+ throw py::import_error (" Failed to load Tcl_SetVar or Tcl_SetVar2 " );
348360 }else if (!TK_FIND_PHOTO) {
349361throw py::import_error (" Failed to load Tk_FindPhoto" );
350362 }else if (!TK_PHOTO_PUT_BLOCK) {