Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make installed tkinter work with Tcl/Tk 9 builds that embed the Tk script library in the Tk DLL on Windows.
41 changes: 39 additions & 2 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Copyright (C) 1994 Steen Lumholt.
# include <tk.h>
#endif

#if defined(MS_WINDOWS) && TK_MAJOR_VERSION >= 9
# include <tkPlatDecls.h>
#endif

#include "tkinter.h"

#if TK_HEX_VERSION < 0x0805020c
Expand Down Expand Up @@ -175,6 +179,39 @@ _get_tcl_lib_path(void)
}
#endif /* MS_WINDOWS */

#if defined(MS_WINDOWS) && TK_MAJOR_VERSION >= 9
static void
mount_tk_dll_zip(void)
{
HINSTANCE tk_module = Tk_GetHINSTANCE();
wchar_t tk_path[MAX_PATH];
DWORD path_len = GetModuleFileNameW(tk_module, tk_path, MAX_PATH);

if (path_len == 0 || path_len >= MAX_PATH) {
return;
}

Tcl_DString utf8_path;

Tcl_DStringInit(&utf8_path);
Tcl_WCharToUtfDString(tk_path, path_len, &utf8_path);
(void) TclZipfs_Mount(NULL, Tcl_DStringValue(&utf8_path),
"//zipfs:/lib/tk", NULL);
Tcl_DStringFree(&utf8_path);
}
#endif

int
Tkinter_TkInit(Tcl_Interp *interp)
{
#if defined(MS_WINDOWS) && TK_MAJOR_VERSION >= 9
/* Tcl/Tk 9 may embed the tk_library in the Tk DLL which tcl_findLibrary
does not search. Mount the DLL using Zipfs if possible. */
mount_tk_dll_zip();
#endif
return Tk_Init(interp);
}

/* The threading situation is complicated. Tcl is not thread-safe, except
when configured with --enable-threads.

Expand Down Expand Up @@ -544,7 +581,7 @@ Tcl_AppInit(Tcl_Interp *interp)
return TCL_OK;
}

if (Tk_Init(interp) == TCL_ERROR) {
if (Tkinter_TkInit(interp) == TCL_ERROR) {
PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
return TCL_ERROR;
}
Expand Down Expand Up @@ -2988,7 +3025,7 @@ _tkinter_tkapp_loadtk_impl(TkappObject *self)
return NULL;
}
if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) {
if (Tk_Init(interp) == TCL_ERROR) {
if (Tkinter_TkInit(interp) == TCL_ERROR) {
Tkinter_Error(self);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/tkappinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Tcl_AppInit(Tcl_Interp *interp)
return TCL_OK;
}

if (Tk_Init(interp) == TCL_ERROR) {
if (Tkinter_TkInit(interp) == TCL_ERROR) {
return TCL_ERROR;
}

Expand Down
2 changes: 2 additions & 0 deletions Modules/tkinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
(TK_RELEASE_LEVEL << 8) | \
(TK_RELEASE_SERIAL << 0))

int Tkinter_TkInit(Tcl_Interp *interp);

#endif /* !TKINTER_H */
Loading