Pcbnew (python plugin) Mac Tkinter Error

Hello. I need to run a tkinter GUI with python plugin in Pcbnew. This plugin is running without error on Windows and Ubuntu. But when I try to run this plugin on Mac OS Sierra 10.12.6, it shutdowns Pcbnew immediately. I also tested tkinter with Scripting Console inside Pcbnew. This is what I do:

import Tkinter

After this Pcbnew is not shutting down but it freezes. Any ideas?

This is my version info:

Application: Pcbnew
Version: (5.1.5-0), release build
wxWidgets 3.0.4
libcurl/7.54.0 SecureTransport zlib/1.2.8
Platform: Mac OS X (Darwin 16.7.0 x86_64), 64 bit, Little endian, wxMac
Build Info:
wxWidgets: 3.0.4 (wchar_t,STL containers,compatible with 2.8)
Boost: 1.69.0
OpenCASCADE Community Edition: 6.9.1
Curl: 7.54.0
Compiler: Clang 9.0.0 with C++ ABI 1002
Build settings:

1 Like

Since there is no other answer yet, i had a much better experience using wxPython over tkinter. I have no MAC at hand nor do i know how to use one so i am sorry to be not much more of a help but maybe you can checkout wxPython.

Kicad crashing is never good and you can report that on gitlab right away. Someone with debug build may be able to find what is causing the issue.
That said if you are not committed to tkinter look at wxpython, it is proven to work fine by many plugins out there.

KiCad on macOs uses python supplied by KiCad and not the system python. (Try import pcbnew from your normal python prompt and it will fail on macOs). You can show what is available in the KiCad python path by doing an

import sys
print sys.path

from the KiCad console.

You will also find that neither pip nor easy_install are available within the KiCad python environment, so that you cannot (easily) add any other python modules. You can work around this by importing the KiCad site packages into your system python and working from there. I really don’t know why macOS KiCad Python seems to be so different to other 'nix OS installs.

1 Like

It might be a good solution but this way you cannot open the plugin inside KiCad, it should be opened from outside. I think it is not user friendly. I tried to run a plugin that calls the system python and runs the plugin with Tkinter(via subprocess), but it also failed.

Having had another play with this, it does seem possible to import an external TkInter to the Kicad python as follows.

Py 0.9.8
Python 2.7.16 (default, Nov 26 2019, 02:03:00) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on Darwin
Type "help", "copyright", "credits" or "license" for more information.
Startup script executed: /Users/johnpateman/Library/Preferences/kicad/PyShell_pcbnew_startup.py
>>> import sys
>>> sys.path.insert(0,"/usr/local/lib/python2.7/site-packages/tkinter")
>>> import Tkinter as tk
>>> print tk.TkVersion

The console reports that tk functions have been successfully imported into the namespace but if you try and define a root widget, it still crashes. I don’t know enough about Tk to investigate this further.

Thank you for your answer. KiCad’s local python contains Tkinter, so importing it was not a problem. I will try debug build to investigate the error. Maybe I can find something about crashing.

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