Thursday, October 9, 2025
HomeLanguageswxPython – Destroy button widget using Destroy() function

wxPython – Destroy button widget using Destroy() function

In this article we will learn that, how can we destroy a button widget from a window using Destroy() function in wx.Button class of wxPython. Destroy() function is used to simply destroy a window or widget safely.
Destroy() returns True if the window has either been successfully deleted, or it has been added to the list of windows pending real deletion.

Syntax: wx.StaticText.Destroy(self)

Parameters: Destroy() function takes no arguments.

Return Type: bool

Returns: True if the window has either been successfully deleted, or it has been added to the list of windows pending real deletion.

Code Example:




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.InitUI()
  
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
  
        # create parent panel
        self.pnl = wx.Panel(self)
         
        # create a button at point (20, 50)
        self.btn1 = wx.Button(self.pnl, id = 1, label ="Remove Text", pos =(20, 50))
  
        # create button to destroy
        self.btn0 = wx.Button(self.pnl, id = 1, label ="Click button to remove", pos =(20, 20))
  
        # bind Onclick() function with button
        self.btn1.Bind(wx.EVT_BUTTON, self.Onclick)
  
  
        self.SetSize((350, 250))
        self.SetTitle('wx.Button')
        self.Centre()
  
    def Onclick(self, e):
        # destroy btn0 button
        self.btn0.Destroy()
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output Window:

before Destroy()


after Destroy()

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS