Search code examples
pythonif-statementwxpythongoto

wxPython - if condition = False then skip some lines or exit without closing Main Frame


in my wxApp that is currently under development, I have bind a button to call a new frame. However I want to put condition in my def that is actually calling the new frame and if that fails the def method should simple exit but not close the main Frame. So basically something like Exit Sub in VBA. Below is my code:-

self.btn_CreateItem.Bind(wx.EVT_BUTTON, self.CreateBtnClicked)

def CreateBtnClicked(self, event):
    if self.rgnCombo.GetValue() == '':
        ctypes.windll.user32.MessageBoxA(0, "Can't create item without selecting Region!!!", '', 1)
        exit()
    call_CreateFrame = CreateItemFrame(None, 'Create work item(s)!!!')

so in place of exit() in the code above (because it is closing the whole main frame) I want something equivalent to VBA's Exit Sub.

Also is there a way to also skip some scripts and continue from a certain line like the GoTo method of VBA.


Solution

  • Replace

    exit()
    

    with

    return
    

    The equivalent of a GOTO in python