Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

wxPython – SetLabel() function in wx.Button

  • Last Updated : 18 Jun, 2020

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:

ParameterInput TypeDescription
labelstringThe 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!