wxPython Dialog self.Destoy()将冻结应用程序

时间:2012-08-28 15:40:34

标签: python wxpython boa-constructor

我使用Python 2.6和wxPython 2.8.12通过BoaConstructor开发应用程序。我有一个编程的应用按钮,它将存储来自TextCtrl的一些变量,然后在对话框窗口上执行self.Destroy()调用以关闭它。当我单击此按钮时,GUI挂起并且应用程序冻结。但是,如果我不调用self.Destroy(),我可以在没有问题的情况下存储变量,直到我尝试使用窗口右上角的X按钮关闭窗口(使用print命令测试)。如果我不尝试存储任何变量,只需按下按钮执行self.Destroy(),一切都很好。只有当我尝试存储变量并执行GUI挂起的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()

编辑:这是指Mike的建议。这些是我测试的较小程序的两个文件,它们运行完美。

#!/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()

谢谢!

1 个答案:

答案 0 :(得分:0)

原来问题是我自己的编码,我一直怀疑但是无法隔离。由于我捕获值的方式,我有一个无限循环运行。 TextCtrls返回字符串,而不是整数。谁知道。因此,在产生对话框的框架中,i< “StringThatIThoughtWasAnINT”永远不会逃脱。感谢@MikeDriscoll提供的所有帮助!