• Login
Community
  • Login

Import Tkinter in PythonScript on Window

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
8 Posts 2 Posters 1.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P
    Philippe Destrumel
    last edited by Feb 24, 2025, 10:06 AM

    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

    P 1 Reply Last reply Feb 24, 2025, 3:42 PM Reply Quote 0
    • P
      Philippe Destrumel
      last edited by Feb 24, 2025, 3:10 PM

      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

      P 1 Reply Last reply Feb 24, 2025, 3:32 PM Reply Quote 0
      • P
        PeterJones @Philippe Destrumel
        last edited by PeterJones Feb 24, 2025, 3:33 PM Feb 24, 2025, 3:32 PM

        @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 a plugins\PythonScript\lib hierarchy with the various Tcl, Tk, and related library files; if you unzip all of those into your existing c:\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
        • 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
        1 Reply Last reply Reply Quote 2
        • P
          PeterJones @Philippe Destrumel
          last edited by PeterJones Feb 24, 2025, 3:44 PM Feb 24, 2025, 3:42 PM

          @Philippe-Destrumel ,

          Oh, even better: if you download the PythonScript_2.1.0.0_x64.msi or PythonScript_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

          0d402dae-9f0d-4842-9fb4-056edecdd6f2-image.png

          1 Reply Last reply Reply Quote 3
          • P
            Philippe Destrumel
            last edited by Feb 24, 2025, 5:42 PM

            Merci pour vos réponses. J’essaie ça immédiatement.
            Puis vous fait un retour

            1 Reply Last reply Reply Quote 0
            • P
              Philippe Destrumel
              last edited by Feb 24, 2025, 6:35 PM

              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

              P 1 Reply Last reply Feb 24, 2025, 7:04 PM Reply Quote 0
              • P
                PeterJones @Philippe Destrumel
                last edited by Feb 24, 2025, 7:04 PM

                @Philippe-Destrumel ,

                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 your pip found somewhere in c:\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 filename npp_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.)

                1 Reply Last reply Reply Quote 2
                • P
                  Philippe Destrumel
                  last edited by Feb 24, 2025, 7:40 PM

                  I have to go, but I will continue tomorrow.
                  Thank you again for your answers.

                  1 Reply Last reply Reply Quote 0
                  7 out of 8
                  • First post
                    7/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors