Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created November 5, 2018 17:00
Show Gist options
  • Save driscollis/1fd368c33770bc7429119b96dfdc7f63 to your computer and use it in GitHub Desktop.
Save driscollis/1fd368c33770bc7429119b96dfdc7f63 to your computer and use it in GitHub Desktop.
Posting events across frames
import wx
class FrameOne(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='Frame 1')
self.Bind(wx.EVT_CLOSE, self.on_close)
def on_close(self, event):
print('Closing frame 1')
self.Destroy()
class FrameTwo(wx.Frame):
def __init__(self, other_frame):
wx.Frame.__init__(self, other_frame, title='Frame 2')
self.Bind(wx.EVT_CLOSE, self.on_close)
self.other_frame = other_frame
def on_close(self, event):
print('Closing frame 2')
self.Destroy()
wx.PostEvent(self.other_frame, event)
if __name__ == '__main__':
app = wx.App()
frame1 = FrameOne()
frame2 = FrameTwo(frame1)
frame1.Show()
frame2.Show()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment