最近我遇到了下面显示的代码问题,现在一直困扰着我。我不知道为什么会发生这种情况,我唯一知道的是python代码在注明的行上引发了一个段错误,而gdb提出了一些关于内存的东西。我做错了什么或这是一个错误?我真的很想让这个工作,所以如果你能提供帮助,我会非常感激。
C ++代码:
static int win_width = 364;
static int win_height = 478;
netlist = new wxDialog(NULL, wxID_ANY, "Network List", wxDefaultPosition, wxSize(win_width-8, win_height-8), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
wxBoxSizer *hszr = new wxBoxSizer(wxHORIZONTAL),
*vszr = new wxBoxSizer(wxVERTICAL), *vszr2 = new wxBoxSizer(wxVERTICAL);
wxStaticBoxSizer* sszr = new wxStaticBoxSizer(wxVERTICAL, netlist, "User Information");
wxFlexGridSizer* fgszr = new wxFlexGridSizer(2);
fgszr->Add(new wxStaticText(sszr->GetStaticBox(), wxID_ANY, "Nick Name: "));
Python代码:
win_width = 364
win_height = 478
netlist = wx.Dialog(None, wx.ID_ANY, "Network List", wx.DefaultPosition, wx.Size(win_width-8, win_height-8), wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
hszr = wx.BoxSizer(wx.HORIZONTAL)
vszr = wx.BoxSizer(wx.VERTICAL)
vszr2 = wx.BoxSizer(wx.VERTICAL)
sszr = wx.StaticBoxSizer(wx.StaticBox(netlist, wx.ID_ANY, "User Information"), orient=wx.VERTICAL)
fgszr = wx.FlexGridSizer(2)
fgszr.Add(wx.StaticText(sszr.GetStaticBox(), wx.ID_ANY, "Nick Name: ")) # Segmentation Fault
答案 0 :(得分:0)
在python方面,Add
方法具有以下参数:
Add(self, item, int proportion=0, int flag=0, int border=0, userData=None)
proportion
不是id(但是它会默认通过,因为它们都是整数)并且flag
不是字符串。
与C ++版本相比,工作线将是:
fgszr.Add(wx.StaticText(sszr.GetStaticBox(), wx.ID_ANY, "Nick Name: "))
<强>更新强>
使用wxPython 2.9.1.1
在Windows上成功执行以下代码import wx
app = wx.PySimpleApp()
win_width = 364
win_height = 478
netlist = wx.Dialog(None, wx.ID_ANY, "Network List", wx.DefaultPosition, wx.Size(win_width-8, win_height-8), wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
hszr = wx.BoxSizer(wx.HORIZONTAL)
vszr = wx.BoxSizer(wx.VERTICAL)
vszr2 = wx.BoxSizer(wx.VERTICAL)
sszr = wx.StaticBoxSizer(wx.StaticBox(netlist, wx.ID_ANY, "User Information"), orient=wx.VERTICAL)
fgszr = wx.FlexGridSizer(2)
fgszr.Add(wx.StaticText(sszr.GetStaticBox(), wx.ID_ANY, "Nick Name: ")) # Segmentation Fault
netlist.ShowModal()