@@ -92,6 +92,7 @@ static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK;
92
92
// Global vars for Tcl functions. We load these symbols from the tkinter
93
93
// extension module or loaded Tcl libraries at run-time.
94
94
static Tcl_SetVar_t TCL_SETVAR;
95
+ static Tcl_SetVar2_t TCL_SETVAR2;
95
96
96
97
static void
97
98
mpl_tk_blit (py::object interp_obj, const char *photo_name,
@@ -173,7 +174,15 @@ DpiSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
173
174
std::string dpi = std::to_string (LOWORD (wParam));
174
175
175
176
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
+ }
177
186
}
178
187
return 0 ;
179
188
case WM_NCDESTROY:
@@ -246,13 +255,16 @@ bool load_tcl_tk(T lib)
246
255
if (auto ptr = dlsym (lib, " Tcl_SetVar" )) {
247
256
TCL_SETVAR = (Tcl_SetVar_t)ptr;
248
257
}
258
+ if (auto ptr = dlsym (lib, " Tcl_SetVar2" )) {
259
+ TCL_SETVAR2 = (Tcl_SetVar2_t)ptr;
260
+ }
249
261
if (auto ptr = dlsym (lib, " Tk_FindPhoto" )) {
250
262
TK_FIND_PHOTO = (Tk_FindPhoto_t)ptr;
251
263
}
252
264
if (auto ptr = dlsym (lib, " Tk_PhotoPutBlock" )) {
253
265
TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)ptr;
254
266
}
255
- return TCL_SETVAR && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
267
+ return ( TCL_SETVAR || TCL_SETVAR2) && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
256
268
}
257
269
258
270
#ifdef WIN32_DLL
@@ -343,8 +355,8 @@ PYBIND11_MODULE(_tkagg, m, py::mod_gil_not_used())
343
355
throw py::error_already_set ();
344
356
}
345
357
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 " );
348
360
} else if (!TK_FIND_PHOTO) {
349
361
throw py::import_error (" Failed to load Tk_FindPhoto" );
350
362
} else if (!TK_PHOTO_PUT_BLOCK) {
0 commit comments