1

I am trying to create an application in which the GUI is programmed in Python (Tkinter) and I have a library in C++ that I want to interface with this GUI code. (Please, no comments on why the GUI and the application library are in separate languages).

One approach that immediately comes to mind is to compile the C++ library into an executable and write python wrappers that call this executable ( via system() ) with specific arguments and consume the output.

I am not sure what the performance implications are for such an implementation. Also I do not want to change the library into Python. Any better suggestions or comments on the approach?

3
  • 2
    Haven't used it myself, but Boost.Python might be able to help. Commented Feb 17, 2015 at 17:31
  • Launching a C++ executable is a fairly heavyweight operation, so I'd only do that if you didn't have to do it very often. (e.g. no more often than once a second). Another possibility would be to launch the C++ executable once and have it keep running, and then have your GUI code communicate with it via stdin/stdout, TCP socket, or some other IPC mechanism. Commented Feb 17, 2015 at 17:33
  • 2
    possible duplicate of Calling C/C++ from python? Commented Feb 17, 2015 at 17:34

1 Answer 1

2

There are several ways for doing this. One obvious way was already stated by chis. Another good way of interfacing C++ with Python is by using swig. It all comes down how complex your structures / classes are.

So the C++ code is going to be a module in python and can be called by the interface as any other python function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.