[Chicago] using wxPython gui application in c?

Robert Ramsdell rcriii at ramsdells.net
Tue Nov 14 02:41:53 CET 2006


Hello Jolley.  I'm not sure what is going on with your code, but try
this for the Python side of things:

import wx

class MyApp(wx.Frame):
    def __init__(self, title='MyApp'):
        self.app = wx.PySimpleApp()
        self.title = title
        self.windowCaption = title
        wx.Frame.__init__(self,None,wx.ID_ANY, self.windowCaption,
                          size=(200,100),
                          style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)

app = MyApp()
app.mainloop()

I posted a more elaborate example to the list last week.

Robert

On Mon, 2006-11-13 at 16:38 +0800, 放茗 谈 wrote:
> hello,all guys,
>       i am starting to make a python gui app with wxPython, and later
> i want to using c extension to call it.
> there is my python code(app.py):
>  
> from wxPython.wx import *
> class MyApp(wxApp):
>  def OnInit(self):
>   frame = wxFrame(NULL,-1,"Hello from wxPython")
>   frame.Show(true)
>   self.SetTopWindow(frame)
>   return true
> app = MyApp(0)
> app.MainLoop()
>  
> and also the c extension code
>  
> #include "python.h"
> //#include "wxPython.h"
> #include <iostream>
> using namespace std;
> static PyMethodDef g_methodDefinition = {NULL};
> #define ERROR(pyObject,msg) {if (pyObject == NULL){printf("%
> s",msg);PyErr_Print();exit(1);}}
> int main()
> {
>  PyObject
> *pWorkObject,*pModule,*pClass,*pInstance,*pMethod;//,*pWxpythonModule;
>  Py_Initialize();
>  if (!Py_IsInitialized())
>  {
>   cerr << "can not initialize the python object!" << endl;
>   return -1;
>  }
>  //pWxpythonModule = PyImport_ImportModule("wxPython.wx");
>  //ERROR(pWxpythonModule,"cannot load wxPython.wx");
>  
>  //load the module
>  pModule = PyImport_ImportModule((char*)"app");
>  ERROR(pModule,"can not load app module!")
> .//omit some
> when the code comes to import the app module,it crashed.later with
> PyErr_Print,i get the error message is as follow:
> can not load app module!Traceback (most recent call last):
>   File "c:\Program Files\Microsoft Visual Studio\MyProjects
> \runPythonGUI\app.py"
> , line 1, in ?
>     from wxPython.wx import *
>   File "C:\Python24\lib\site-packages\wx-2.6-msw-unicode\wxPython
> \__init__.py",
> line 10, in ?
>     import _wx
>   File "C:\Python24\lib\site-packages\wx-2.6-msw-unicode\wxPython
> \_wx.py", line
> 3, in ?
>     from _core import *
>   File "C:\Python24\lib\site-packages\wx-2.6-msw-unicode\wxPython
> \_core.py", lin
> e 15, in ?
>     import wx._core
>   File "C:\Python24\lib\site-packages\wx-2.6-msw-unicode\wx
> \__init__.py", line 4
> 2, in ?
>     from wx._core import *
>   File "C:\Python24\lib\site-packages\wx-2.6-msw-unicode\wx\_core.py",
> line 4, i
> n ?
>     import _core_
> ImportError: No module named _core_
> Press any key to continue
> though i have added the directory where the pyd lives in sys.path or
> the environment,it doesnot come into effect.also, as the  _core_.pyd
> is accompanied with _core.py and _core.pyc.and it means that it can
> satisfy the basic need that pyd searches the path.and i can make sure
> that the problem can not come because it is a .pyd.
> any suggestions and feedback will be greatly appreciated!
> thanks ,really
> regards,
> jolley
>  
> 
> ______________________________________________________________________
> 雅虎免费邮箱-3.5G容量,20M附件
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago



More information about the Chicago mailing list