正如标题所说,当我实现代码清除暗示文本并运行时,应用程序崩溃了。
据我所知,这只是在Mac OS X 10.8上,但也是我能够运行它。
在其他代码上它确实运行,只有一次我输入文本(在给予焦点后)它会崩溃。但是这个应用程序立即崩溃(我认为与其他小部件无关,所以它立即得到关注)。 更新了示例,因此它不再立即崩溃,现在您必须单击组合框并尝试键入它以使其崩溃。
但是,如果文本看起来不是“”,则不会发生这种情况。
代码
import wx
class MyCrashyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
# another widget to take focus at first otherwise it crashes instantly!
sizer = wx.BoxSizer(wx.VERTICAL)
self.text_ctrl = wx.TextCtrl(self, -1, value = "There are major problems here.\nWithout this to auto take focus this will crash immediatly just by trying to clear the hint.\nNow you have to click on the combo ctrl and try to type.", style = wx.TE_MULTILINE)
self.search_ctrl = wx.ComboBox(self, -1)
self.search_ctrl.SetMinSize((650, -1))
self.search_ctrl.SetSize((650, -1))
self.search_ctrl.SetHint("This is are hint text; once it is clear and you try to type something in it it will crash on Mac OS X")
sizer.Add(self.text_ctrl, flag = wx.EXPAND)
sizer.Add(self.search_ctrl)
self.SetSizer(sizer)
self.FirstTimeSearchGetsFocus = True
self.Bind(wx.EVT_BUTTON, lambda e: e.Skip(), self.text_ctrl)
self.search_ctrl.Bind(wx.EVT_SET_FOCUS, self.OnSearchFocus)
self.text_ctrl.SetFocus()
def OnSearchFocus(self, event):
print "Search Focus"
if 1==1:
print "First time"
# clear the hinted text
self.search_ctrl.SetHint("")
self.search_ctrl.Clear()
self.search_ctrl.Refresh()
self.FirstTimeSearchGetsFocus = False
event.Skip()
if __name__ == "__main__":
app = wx.App(False)
f = wx.Frame(None, -1)
MyCrashyPanel(f)
f.Show()
app.MainLoop()
崩溃报告
[太大了到这里http://pastebin.com/9B1Sgh3P]
答案 0 :(得分:1)
如果它崩溃了,那就是wxWidgets中的一个错误,所以唯一要做的就是: