1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
{
lib,
stdenv,
buildPythonPackage,
replaceVars,
setuptools,
python,
pythonOlder,
tcl,
tclPackages,
tk,
xvfb-run,
}:
buildPythonPackage {
pname = "tkinter";
version = python.version;
pyproject = true;
src = python.src;
prePatch = ''
mkdir $NIX_BUILD_TOP/tkinter
# copy the module bits and pieces from the python source
cp -v Modules/{_tkinter.c,tkinter.h} ../tkinter/
cp -rv Modules/clinic ../tkinter/
cp -rv Lib/tkinter ../tkinter/
# install our custom pyproject.toml
cp ${
replaceVars ./pyproject.toml {
python_version = python.version;
python_internal_dir = "${python}/include/${python.libPrefix}/internal";
}
} $NIX_BUILD_TOP/tkinter/pyproject.toml
''
+ lib.optionalString (pythonOlder "3.13") ''
substituteInPlace "$NIX_BUILD_TOP/tkinter/tkinter/tix.py" --replace-fail \
"os.environ.get('TIX_LIBRARY')" \
"os.environ.get('TIX_LIBRARY') or '${tclPackages.tix}/lib'"
'';
# Adapted from https://github.com/python/cpython/pull/124542
patches = lib.optional (pythonOlder "3.12") ./fix-ttk-notebook-test.patch;
preConfigure = ''
pushd $NIX_BUILD_TOP/tkinter
'';
build-system = [ setuptools ];
buildInputs = [
tcl
tk
];
env = {
TCLTK_LIBS = toString [
"-L${lib.getLib tcl}/lib"
"-L${lib.getLib tk}/lib"
"-l${tcl.libPrefix}"
"-l${tk.libPrefix}"
];
TCLTK_CFLAGS = toString [
"-I${lib.getDev tcl}/include"
"-I${lib.getDev tk}/include"
];
};
nativeCheckInputs = lib.optional stdenv.hostPlatform.isLinux xvfb-run;
preCheck = ''
cd $NIX_BUILD_TOP/Python-*/Lib
export HOME=$TMPDIR
'';
checkPhase =
let
testsNoGui = [
"test.test_tcl"
"test.test_ttk_textonly"
];
testsGui =
if pythonOlder "3.12" then
[
"test.test_tk"
"test.test_ttk_guionly"
]
else
[
"test.test_tkinter"
"test.test_ttk"
];
in
''
runHook preCheck
${python.interpreter} -m unittest ${lib.concatStringsSep " " testsNoGui}
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
xvfb-run -w 10 -s "-screen 0 1920x1080x24" \
${python.interpreter} -m unittest ${lib.concatStringsSep " " testsGui}
''
+ ''
runHook postCheck
'';
pythonImportsCheck = [ "tkinter" ];
meta = {
# Based on first sentence from https://docs.python.org/3/library/tkinter.html
description = "Standard Python interface to the Tcl/Tk GUI toolkit";
longDescription = ''
The tkinter package (“Tk interface”) is the standard Python interface to
the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix
platforms, including macOS, as well as on Windows systems.
Running python -m tkinter from the command line should open a window
demonstrating a simple Tk interface, letting you know that tkinter is
properly installed on your system, and also showing what version of
Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to
that version.
Tkinter supports a range of Tcl/Tk versions, built either with or without
thread support. The official Python binary release bundles Tcl/Tk 8.6
threaded. See the source code for the _tkinter module for more
information about supported versions.
Tkinter is not a thin wrapper, but adds a fair amount of its own logic to
make the experience more pythonic. This documentation will concentrate on
these additions and changes, and refer to the official Tcl/Tk
documentation for details that are unchanged.
'';
homepage = "https://docs.python.org/3/library/tkinter.html";
inherit (python.meta)
license
maintainers
;
};
}
|