Saturday, November 16, 2024
Google search engine
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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments