Import Tkinter in PythonScript on Window
-
Hello,
Window environment, So Python Script (Python version 2.7)
The Tkinter module is not present.
How can I integrate it for my macro?Thanks for your help
Philippe Destrumel
-
Clarification on my Notepad/PythonScript configuration:
Notepad++ v8.7.4 (64-bit)
Build time : Dec 4 2024 - 23:50:05
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
Placeholders : OFF
DirectWrite : ON
Multi-instance Mode : monoInst
File Status Auto-Detection : cdEnabledNew (for current file/tab only)
Dark Mode : OFF
OS Name : Windows 11 Home (64-bit)
OS Version : 23H2
OS Build : 22631.4890
Current ANSI codepage : 1252
Plugins :
jN (2.2.190.21986)
JsMapParser.NppPlugin (4.2)
mimeTools (3.1)
NppConverter (4.6)
NppExec (0.8.8)
NppExport (0.4)
PythonScript (2)
SessionMgr (1.4.4)Thanks for your help
Philippe Destrumel
-
Tkinter doesn’t come by default with the PythonScript plugin. However, since you’re still on v2.0.0, you can go to the v2.0.0 download page, and download the
PythonScript_TclTk_2.0.0.0_x64.zip
. That zipfile contains aplugins\PythonScript\lib
hierarchy with the various Tcl, Tk, and related library files; if you unzip all of those into your existingc:\Program Files\Notepad++\plugins\PythonScript\lib
hierarchy, then exit and restart Notepad++, you(see also this discussion from last year, where @alan-kilborn explains the same steps)
However, I might recommend that instead of sticking with v2.0.0:
- If you need to stay with Python 2.7, there is a newer version of PythonScript v2.1.0 available at https://github.com/bruderstein/PythonScript/releases/tag/v2.1.0, which includes many improvements, including compatibility with Notepad++ v8.7.5-and-newer, so you would be able to upgrade Notepad++ going forward
- you can manually download the
PythonScript_Full_2.1.0.0_x64_PluginAdmin.zip
and unzip it into the appropriate directories, to install the base PythonScript v2.1.0- you may have to uninstall the old copy first; I haven’t tried this sequence. But it might be easier to upgrade Notepad++ to v8.7.5 or newer, then use Plugins Admin to upgrade PythonScript to v2.1.0
- then you would grab and unzip
PythonScript_TclTk_2.1.0.0_x64.zip
to get the Tcl/Tk libraries
- you can manually download the
- If you only deal with UTF-8 files, and you would rather ditch the old Python 2.7 and move to Python 3.12, you can use the most recent alpha release of PythonScript 3 – currently at 3.0.21 https://github.com/bruderstein/PythonScript/releases/tag/v3.0.21
- you would uninstall the old PythonScript using the Plugins Admin
- then grab and unzip
PythonScript_Full_3.0.21.0_x64_PluginAdmin.zip
- then grab and unzip
PythonScript_TclTk_3.0.21.0_x64.zip
- If you need to stay with Python 2.7, there is a newer version of PythonScript v2.1.0 available at https://github.com/bruderstein/PythonScript/releases/tag/v2.1.0, which includes many improvements, including compatibility with Notepad++ v8.7.5-and-newer, so you would be able to upgrade Notepad++ going forward
-
Oh, even better: if you download the
PythonScript_2.1.0.0_x64.msi
orPythonScript_3.0.21.0_x64.msi
(as appropriate), then it will install the full PythonScript plugin with Python 2.7 or 3.12, and it will give you the option of installing the Tcl/Tk libraries at the same time. That’s probably the easiest way.So my new recommendation is:
- If you want to stick with Python 2.7, download and run the 2.1.0.0 MSI installer, and choose to add in the Tcl/Tk libraries when prompted for optional portions
- If you only deal with UTF-8 (or only use standard US ANSI text), and want to switch to Python 3.12, you should
- uninstall Python 2.0.0.0 using Plugins Admin
- download and run the 3.0.21 MSI (future readers should look for the most recent alpha version), choosing Tcl/Tk when prompted for optional portions
-
Merci pour vos réponses. J’essaie ça immédiatement.
Puis vous fait un retour -
The problem moves. TKinter.py is there, but another file is missing : _tkinter
What I did:
- downloaded PythonScript_ExtraLibs_2.0.0.0_x64.zip
- copied the contents of the lib folder of this zip into notepad++:
-> c:\Program Files\Notepad++\plugins\PythonScript\lib
An error is raised:
Thank you for your help
Traceback (most recent call last): File "C:\Users\33684\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\npp_inspect_js.py", line 120, in <module> import Tkinter as tk File "C:\Python27\Lib\lib-tk\Tkinter.py", line 38, in <module> import FixTk File "C:\Python27\Lib\lib-tk\FixTk.py", line 65, in <module> import _tkinter ImportError: DLL load failed: Le module sp飩fi頥st introuvable.
Afficher le dictionnaire
21 / 5 000 -
I cannot tell from your description whether you just installed ExtraLibs, or whether you did TclTk and ExtraLibs. You need to do the TclTk.
Also, your traceback is implying that it’s trying to use your
c:\python27\
installation of Python, rather than using the one in the PythonScript plugin. Could you confirm for us whether you have Plugins > Python Script > Configuration… set such that☐ Prefer installed Python libraries - ...
is checkmarked? If it is, then you need to use yourpip
found somewhere inc:\python27\...
hierarchy to install Tkinter there, rather than installing the copy of Tkinter for the Python Script plugin.(I personally don’t recommend using the “installed Python libraries”, as that tends to confuse users as to the purpose of PythonScript – it is not a plugin for developing random programs in Notepad++, it is a way to use the Python language to automate Notepad++. But using the “installed Python libraries” does give the benefit of you’ve got the full
pip
interface for the installed version, so it makes it much easier to add libraries, if you need them for what you’re doing inside Notepad++, so I don’t say “don’t do it”, I just personally don’t suggest doing so for N++ users. Since your script’s filenamenpp_inspect_js.py
implies you are doing something inside Notepad++ with the script, I am not saying that you don’t understand the difference… but I just wanted to clarify for other readers.) -
I have to go, but I will continue tomorrow.
Thank you again for your answers.