2009年2月12日 星期四

Embedded Python + wxPython

上一篇依樣,只是這次是用另依種Embedded的方法
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, u"你好, 世界")
frame.Show(True)
app.MainLoop()
要注意的是,這次是用file open所以設定PYTHONPATH是沒用得。要改的是open file的路徑。
#include <Python2.5/Python.h>
#include <stdio.h>
//將SCRIPT_PATH設定成py檔和執行檔的相對路徑
#define SCRIPT_PATH "/"
int main(int argc, char* argv[]) {
char pch[1024]={0};
char scriptpath[1024]={0};
int i=strrchr(argv[0],'/')-argv[0];
strncpy (pch,argv[0],i);
strcpy(scriptpath,SCRIPT_PATH);
strcat(pch,scriptpath);
strcat(pch,"/gui.py");
FILE *fp;

Py_Initialize();
fp = fopen(pch, "r");
PyRun_SimpleFile(fp, "gui.py");
fclose(fp);

Py_Finalize();
}
如果你遇到如下的問題
This program needs access to the screen.
Please run with 'pythonw', not 'python', and only when you are logged
in on the main display of your Mac.
請參考,http://yycking.blogspot.com/2009/02/mac_12.html

沒有留言: