Re: events in wx python

Events are automatically triggered when something occurs, these triggers are set up by binding an action to watch for and then call a function when it happens. The event itself contains an ID for the menu item its appart of, or any relevant state data, like mouse clicks, position, etc. You can use global bindings to monitor for events in the window like the mouse going out of bounds, which would then automatically trigger a binding that calls a function with an event when it happens. For example:

import wx

#this recieves an event when the binding is triggered
def OnClose(event):
    dlg = wx.MessageDialog(top, 
        "Do you really want to close this application?",
        "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
    result = dlg.ShowModal()
    dlg.Destroy()
    if result == wx.ID_OK:
        top.Destroy()

app = wx.App(redirect=True)
top = wx.Frame(None, title="Hello World", size=(300,200))
#this binds the action of the window closing, which calls OnClose, passing it an event
top.Bind(wx.EVT_CLOSE, OnClose)
top.Show()
app.MainLoop()
-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : SkyGuardian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : SkyGuardian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : SkyGuardian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector

Reply via email to