Frame with events: on close, on close window : Frame « wxPython « Python Tutorial






Frame with events: on close, on close window
import wx

class InsertFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Frame With Button',size=(300, 100))
        panel = wx.Panel(self)
        button = wx.Button(panel, label="Close", pos=(125, 10),size=(50, 50))
        self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def OnCloseMe(self, event):
        self.Close(True)

    def OnCloseWindow(self, event):
        self.Destroy()

app = wx.PySimpleApp()
frame = InsertFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()








19.15.Frame
19.15.1.Set the size of windowSet the size of window
19.15.2.Default frame styleDefault frame style
19.15.3.Creating and Showing a FrameCreating and Showing a Frame
19.15.4.Display a frameDisplay a frame
19.15.5.Set top windowSet top window
19.15.6.Frame that displays an image.
19.15.7.Adding Labels and Titles with Keyword ArgumentsAdding Labels and Titles with Keyword Arguments
19.15.8.Frame with events: on close, on close windowFrame with events: on close, on close window
19.15.9.On init and on exitOn init and on exit
19.15.10.Bind key event and button eventBind key event and button event
19.15.11.Set frame propertiesSet frame properties
19.15.12.Add contro to frame and layout themAdd contro to frame and layout them
19.15.13.Subclass frameSubclass frame
19.15.14.Help ContextHelp Context