HomeLanguageswxPython – SetLabel() function in wx.Button

wxPython – SetLabel() function in wx.Button

In this article we are going to learn about SetLabel() function associated with wx.Button class of wxPython. SetLabel() function is used to set the string label for the button.

It takes a string parameter that is used as label for button.

Syntax: wx.Button.SetLabel(self, label)

Parameters:

Parameter Input Type Description
label string The label to set.

Code Example:




import wx
  
class Mywin(wx.Frame):
  
    def __init__(self, parent, title):
        super(Mywin, self).__init__(parent, title = title, size =(250, 150))
        self.InitUI()
  
    def InitUI(self):
        self.panel = wx.Panel(self)
        self.btn = wx.Button(self.panel, label ="Click", pos =(75, 10))
        self.btn.Bind(wx.EVT_BUTTON, self.Onclick)
  
        self.SetMinSize((400, 250))
        self.Centre()
        self.Show(True)
  
    def Onclick(self, event):
        # SET A STRING LABEL FOR BUTTON
        self.btn.SetLabel("Clicked")
  
  
ex = wx.App()
Mywin(None, 'Window')
ex.MainLoop()


Output Window:

before clicking button


after clicking button

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

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS