我正在使用 Python 2.6 和 wxPython 2.8.12 通过 BoaConstructor 开发应用程序。我编写了一个应用按钮,以便它将存储来自 TextCtrl 的一些变量,然后在对话框窗口上执行 self.Destroy() 调用以关闭它。当我单击此按钮时,GUI 挂起并且应用程序冻结。但是,如果我不调用 self.Destroy(),我可以毫无问题地存储变量,直到我尝试使用窗口右上角的 X 按钮关闭窗口(使用打印命令进行测试)。如果我不尝试存储任何变量而只是在按下按钮时执行 self.Destroy() ,一切都很好。只有当我尝试存储变量并执行 self.Destroy() 时,GUI 才会挂起。任何机构都可以伸出援手吗?提前致谢。
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()
谢谢!