KiCad 6 tkinter

Hi, I would like to use tkinter in my script, but since KiCad 6, there is an error while loading the tkinter module:

import tkinter
Traceback (most recent call last):
File “”, line 1, in
File “C:\Program Files\KiCad\6.0\bin\Lib\tkinter_init_.py”, line 37, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named ‘_tkinter’

Any idea how to solve this? It seems that the tk is installed properly (pip install tk).
Thank you

Kicad6 uses python3 so may be the library is installed for this.

I can’t say if this is the problem you’re having but, sometime during Kicad’s evolution and my using tkinter, I had similar problem and discovered the culpret: Upper/Lower case

Try this:
import Tkinter

I have run into the same problem, although I don’t really need tk. KiCad’s python has access to the wx UI library and I would prefer that.

I found this: python - ImportError: No module named 'Tkinter' - Stack Overflow, and especially https://stackoverflow.com/a/59970646.

It’s possible that the embedded python in the KiCad installation doesn’t have tk.

Actually in KiCad v6 it should be import tkinter because it was changed that way in python. KiCad v6 uses more recent python.

It does but it doesn’t

Python2 → Python3 did rename that package (Tkinter → tkinter) but it does look like it has not been included in Kicad’s packaging for windows.
Linux distributions can have it as kicad uses the system-wide python

Because windows is … windows kicad has to bundle Python, now the py files are there ( KiCad\6.0\bin\Lib\tkinter) but the so/pyd/dll are not. There is a packaging oversight somewhere

  1. additional files being bundled when they shouldn’t be
  2. build of python3 on the windows machine is incomplete.

While kicad does ship with wx, tkinter is quite good for making crude UI very quickly

KiCad6 provides a shell to allow using pip on KiCad’s python install. Look in the start menu and you should see these:
2022-01-12 09_46_18-Window
Use the KiCad Command Prompt to use pip to install packages for KiCad’s python.

The wrinkle is I honestly don’t know how pip handles partial installs as you describe, but at least it is something for @jerabj to try.

1 Like

Hello.

I’m new here. Can someone please tell me how it is going on with T(t)kinter and Python 3 ? I found it very flexible to build on KiCad 5.1.6 with Python and Tkinter’s own scripts. Now I have the impression that generally there are no interests anymore to implement tkinter because there are interests to develop an API in/with Python. Or is there a possibility to implement tkinter ?

Uli

The KiCad Windows build process which is used for the official Windows packages uses vcpkg system to download the python interpreter. The relevant vcpkg data is here: https://github.com/microsoft/vcpkg/blob/5cf60186a241e84e8232641ee973395d4fde90e1/ports/python3/portfile.cmake#L108. As you can see in line 108, tkinter is disabled. I don’t know why.

Hello.

Many thanks for your response. That’s a important information! I think that’s very difficult to tell the developers because the problem has been known for 4 years. They certainly have completely different problems, I think. As far as I have read, the developers want to develop Tkinter through another API. That may be good, but as long as this new API is not finished - I suspect - it was not advisable to take out Tkinter. It would be good if the developers reactivate this in the foreseeable future.

This may not help but, it’s good Food for thought (?)…

Though the general scheme/logic of Coding Python is the same as for most other languages, I have a very low opinion of Python, verrry low!

I am able to run my Tkinter, Zelle, pyQt, and other Python codes as Stand-Alone programs but, the only Python codes I can run from within Kicad are my wxpython plugins.

However, it’s easy to run non-python programs from Kicad plugin’s (example below).

Though I am able to click a plugin button that attempts to run an external Python code, without errors, the actual code does not execute. I tried various ways so, I suspect my problem has to do with Python and it’s File locations (and the PITA of python…)

That’s the Bad news. The Good news is can run other codes/apps all day from Kicad plugins without problems. And, given I prefer coding Java (especially using Eclipe-IDE’s Java Window-Builder) I stopped hoping to solve the Tkinter/other problem.

Examples of Running some of my codes…

RunOthers

KiCad is built with the wx toolkit.
So, wx and wxPython should be available:

Tkinter is a completely different toolkit, as are Qt and gtk. Generally, you can’t combine two toolkits in the same application/process.

Python tkinter GUI works inside KiCad.

@dschwert I think most folks here looking at Plugins know wxPython is the basis for Kicad. That’s why my wx plugins work.

Having tried unsuccessfully to get NON-wx codes to run inside Kicad is a PITA for me (as I said, they run outside of Kicad. Thus, for ‘me’, the problem’s most likely are the Paths to the files and linking them to run from Kicad/wx.

But, I have No use for outside python codes. I do use my outside Java codes and all works well.

I don’t understand what you are saying. The KiCad developers have nothing to do with vcpkg python/tck/tk. KiCad on Windows, compiled with msvc, uses what’s available through vcpkg, and the python3 installation through vcpkg doesn’t have tcl/tk compiled in, so tkinter doesn’t work in the KiCad’s python installation.

“Tkinter through another API” – I don’t understand this at all.

Nothing has been taken out by KiCad developers, nothing can be reactivated.

ub007 might be confused as Kicad5 on windows did package tkinter. So tkinter used to work with KiCad. But it was build with GCC. Now the transition to MSVC was done for a couple of reasons. GCC build was based upon MSYS and for some reason IIRC transition from python 2.7 to python 3.x was blocked by one of the dependencies (wxpython I think). In order to move from python 2.7 to 3.x the build was moved to MSVC. The other reason for this is that most of packages which require compiled code (numpy) on Windows are build against MSVC. So if you want to use those packages, the interpreter has to be build using the same compiler.

And as already said, MSCV does not package tkinter.

But I don’t see this as a big issue. I’ve made a couple of plugins for V5 with tkinter and with wxpython, and wxpython based plugins integrate much nicely with KiCad. And you can design the GUI using wxformbuilder. The only downside I can see if you want to build standalone programs ebased on tkinter which also have access to pcbnew python API. With MSVC build on windows this is not possible. I would suggest you should reconsider writing the program with wxpython. Both wxpython and tkinter are based upon the same paradigm and have almost the same features.

For the stubborn, IIRC there is an option of building KiCad V6 using MSYS without wxpython (but with python)

Anyway, the the proper solution to get tkinter to the current Windows KiCad package would be to go to the 3rd party vcpkg project and add tk there, then enable tkinter in python3 of vcpkg. Then KiCad and other projects which use vcpkg could have tkinter.

It’s time to leave Tkinter behind…

Actually, wxPython is not too hard to get started with.
The basics can be learned within a few hours:

  • Download and extract the wxGlade GUI builder from wxGlade - Browse /wxglade/1.0.4 at SourceForge.net
  • Then run wxglade.py with the KiCad Python interpreter, e.g. "C:\Program Files\KiCad\6.0\bin\python.exe" "D:\Python\wxglade\_releases\wxGlade-1.0.4\wxglade.py"
  • Work through the wxGlade tutorial, available from Help → Manual.
    The target audience of the tutorial includes people that have not used wxPython before.

If you want to use a standalone Python version instead, I would recommend to stick to the same wxPython revision that KiCad uses. Currently it’s at 4.1.0.

My knowledge of KiCad is rather basic as I’m currently using Eagle. I would be interested in including a KiCad example into the wxGlade distribution, though.

It’s a pity that the GUI code of KiCad and FreeCAD is not written in Python. That would make contributions much easier.

Regards,
Dietmar

Hello, everyone.

Well, I’m a fan if something improves or there is something new. If Wxpython is running in KiCad, then it is great. I will try it. To make it short … I got tkinter under KiCAD6.0.1 to run. Ok, if that’s good or bad - we’ll see it. I can only recommend to download and install Python 3.9. and look at the directories. There are parallels to KiCad. It is not just to copy the TCL / TK -DLLs but you have also to copy some more few directories. But then Tkinter runs as usual. I do not want to go into it how difficult it could have been kiCad to compile via MSVC. Great job, really! I was just astonished why Tkinter was no longer available. Of course TCL / TK is very old - but it works. I will definitely look in Wxpython.
Thank you all here!

P.S.: When you’re starting with wxPython, then you should also download and run the wxPython demo.

It can be found at Index of /wxPython4/extras

Go to the directory matching your wxPython versionand download the ...demo...tar.gz archive.
Then run the demo.py file with your Python interpreter.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.