Hi everybody :)

I have a big problem with embedded Python. I develop a plugin for a C++ application and want to "teach" this app Python Scripting, that users are able to script their own functions.

the App = The C++ Application
plugin = my plugin I develop for the App

The plugin is a object-class which is registered by the App at startup and after that I am able to create many objects of that. The app allocates for every plugin a memory-space (not editable. more code means more allocated memory.

1. the app works when I enter a Python script that calculates something. (output = input + 1)
that still works

2. the app crashs when I generate via Tkinter or another GUI a GUI window with "hello world" in it. The PyRun_Simplestring command is called in the object class when a method is called by the app

3. the app doesn't crash when I use the same code from point 2, but put it outside the allocated class (for example to the point where the class is registered). The app starts, the GUi shows, and after I close it, everything runs further.

What can I do? When I create my own short command-line C++ Tool with a object-class (which isn't needed to allocate) everything runs too). Only in my plugin in the object-class it crashes :(

Py_Initialize();
PyRun_SimpleString("from Tkinter import *");
PyRun_SimpleString("root = Tk()");
PyRun_SimpleString("w = Label(root, text='Hello, world!')");
PyRun_SimpleString("Outport = 5 ** 4");
PyRun_SimpleString("w.pack()");
PyRun_SimpleString("root.mainloop()");
Py_Finalize();

Thanks for your biiig help. Thanks

Bye

donnerCobra

Pardon my curiosity, but what C++/Python package are you using?

Hi! You mean, how do I embed Python C++?

I load in the Python Framework on Mac avaible on Python.org (version 2.5).

Bye :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.