我使用Python 2.6和wxPython 2.8.12通过BoaConstructor开发应用程序。我已经编程了一个应用按钮,这样它就可以存储TextCtrl中的一些变量,然后执行self。Destroy()调用对话框窗口以关闭它。当我单击此按钮时,GUI将挂起,应用程序将冻结。然而,如果我不叫自己。Destroy(),我可以毫无问题地存储变量,直到我尝试使用窗口右上角的X按钮关闭窗口(使用打印命令测试)。如果我不尝试存储任何变量,而只是执行一个self。按下按钮即可销毁(),一切都很好。只有当我尝试存储变量并执行self时,才会出现这种情况。Destroy()。有人能伸出援手吗?提前谢谢。
def OnApplyButton(self, event):
print self.IMSINumberDigitTextCtrl.GetValue()
if self.IMSINumberDigitCheckBox.GetValue() == True:
print self.IMSINumberDigit #Debugging purposes only. Returns expected value
print self.IMSINumberDigitTextCtrl.GetValue() #Debugging purposes only. Returns expected value
self.IMSINumberDigit = self.IMSINumberDigitTextCtrl.GetValue()
print self.IMSINumberDigit #Debugging purposes only. Returns expected value
self.Destroy()
编辑:这是迈克的建议。这是我测试的小程序的两个文件,它们运行得很完美。
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import Frame1
modules = {'Frame1': [1, 'Main frame of Application', u'Frame1.py']}
class BoaApp(wx.App):
def OnInit(self):
self.main = Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
和
#Boa:Frame:Frame1
import wx
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1APPLY, wxID_FRAME1CHECKBOX1, wxID_FRAME1CHECKBOX2,
wxID_FRAME1TEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(5)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(480, 245), size=wx.Size(279, 135),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(279, 135))
self.checkBox1 = wx.CheckBox(id=wxID_FRAME1CHECKBOX1, label='checkBox1',
name='checkBox1', parent=self, pos=wx.Point(24, 16),
size=wx.Size(95, 22), style=0)
self.checkBox1.Bind(wx.EVT_CHECKBOX, self.OnCheckBox1Checkbox,
id=wxID_FRAME1CHECKBOX1)
self.checkBox2 = wx.CheckBox(id=wxID_FRAME1CHECKBOX2, label='checkBox2',
name='checkBox2', parent=self, pos=wx.Point(48, 48),
size=wx.Size(95, 22), style=0)
self.checkBox2.Enable(False)
self.checkBox2.Bind(wx.EVT_CHECKBOX, self.OnCheckBox2Checkbox,
id=wxID_FRAME1CHECKBOX2)
self.Apply = wx.Button(id=wxID_FRAME1APPLY, label=u'Apply',
name=u'Apply', parent=self, pos=wx.Point(24, 88),
size=wx.Size(232, 29), style=0)
self.Apply.Bind(wx.EVT_BUTTON, self.OnApplyButton, id=wxID_FRAME1APPLY)
self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
parent=self, pos=wx.Point(160, 44), size=wx.Size(80, 27), style=0,
value='textCtrl1')
self.textCtrl1.SetEditable(True)
self.textCtrl1.Enable(False)
def __init__(self, parent):
self._init_ctrls(parent)
self.TextCtrlVariableHolder = None
def OnCheckBox1Checkbox(self, event):
value = self.checkBox1.GetValue()
if value == True:
self.checkBox2.Enable(True)
else:
self.checkBox2.Enable(False)
def OnCheckBox2Checkbox(self, event):
value = self.checkBox2.GetValue()
if value == True:
self.textCtrl1.Enable(True)
else:
self.textCtrl1.Enable(False)
def OnApplyButton(self, event):
print self.textCtrl1.GetValue()
if self.checkBox2.GetValue() == True:
print self.TextCtrlVariableHolder
print self.textCtrl1.GetValue()
self.TextCtrlVariableHolder = self.textCtrl1.GetValue()
print self.TextCtrlVariableHolder
self.Destroy()
谢谢!
原来问题出在我自己的编码上,我一直怀疑它,但无法隔离。由于我获取值的方式,我有一个无限循环在运行。TextCtrls返回字符串,而不是int。谁知道呢。因此,在对话框产生的框架中,i<"StringThatIThoughtWasAnINT"永远无法逃脱。感谢您的帮助@MikeDriscoll!