Hello,
I am trying to actually call a GUI from my C++ code which would have buttons and therefore can call functions from C++ again, ie extend the C++ code also.
I am faced with a peculiar problem. I actually tried out an embedding code (downloaded from the net) which actually calls any function which has a text display but when I try to call any code which opens cleanly in python prompt it crashes.
To make matters more concrete let me paste the code of C++ to Python call.
#include <Python.h>
int main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pFunc, *pValue;
if (argc < 3)
{
printf("Usage: exe_name python_source function_name\n ");
return 1;
}
// Initialize the Python Interpreter
Py_Initialize() ;
PyRun_SimpleStr ing("import sys");
PyRun_SimpleStr ing("sys.path.a ppend(\"./ui\")");
// Build the name object
pName = PyString_FromSt ring(argv[1]);
// Load the module object
pModule = PyImport_Import (pName);
// pDict is a borrowed reference
pDict = PyModule_GetDic t(pModule);
// pFunc is also a borrowed reference
pFunc = PyDict_GetItemS tring(pDict, argv[2]);
if (PyCallable_Che ck(pFunc))
{
PyObject_CallOb ject(pFunc, NULL);
} else
{
PyErr_Print();
}
// Clean up
Py_DECREF(pModu le);
Py_DECREF(pName );
// Finish the Python Interpreter
Py_Finalize();
return 0;
}
Now my understanding is that when this code is run, for any python module it should be able to call the function. I actually tried out the multiply function available and it gives correct results.
But if I do <program> Tkinter _test() , instead of a Tk window popping up the program crashes.
I would be very thankful if anyone can suggest where can I go wrong in this since I am a total newbie in GUI and Python.
Regards
Sumanta