Skip to content
Related Articles

Related Articles

wxPython – Change Button Label Font

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 06 Jan, 2022

In this article we are going to learn that how can we change the font of the label text present on the button present in the frame. We need to follow some steps as follows:

Step 1: Create a wx.Font object. 
Step 2: Add different attributes of font in parameters like: family, style etc. 
Step 3: Set font by using SetFont() function.


Syntax: wx.Button.SetFont(self, font)

ParameterInput TypeDescription
fontwx.FontFont for the button label.


Code Example: 


import wx
class Example(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        self.pnl = wx.Panel(self)
        # wx.Font object initialization
        font = wx.Font(12, wx.FONTFAMILY_MODERN, 0, 90, underline = False,
     faceName ="")
        # CREATE BUTTON AT POINT (20, 20) = wx.Button(self.pnl, id = 1, label ="Button", pos =(20, 20),
                                size = wx.DefaultSize,  name ="button")
        self.SetSize((350, 250))
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output Window: 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!