Skip to content
Related Articles
Open in App
Not now

Related Articles

wxPython – Add Image in Button

Improve Article
Save Article
Like Article
  • Last Updated : 24 Jun, 2020
Improve Article
Save Article
Like Article

In this article we are going to learn that, how can we add image in a button. So first of all we will create a wx.Bitmap object and initialize with the image we want to add to button. After this we will use SetBitmap() function associated with wx.Button class of wxPython.

SetBitmap() function takes wx.Bitmap object as parameter.

Syntax: wx.Button.SetBitmap(self, bitmap)


Parameter Input Type Description
bitmap wx.Bitmap Bitmap set for button.

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)
        # create parent panel for button
        self.pnl = wx.Panel(self)
        # create wx.Bitmap object 
        bmp = wx.Bitmap('pointer.png')
        # create button at point (20, 20) = wx.Button(self.pnl, id = 1, label ="Button", pos =(20, 20),
                                        size =(100, 30),  name ="button")
        # set bmp as bitmap for button
        self.SetSize((350, 250))
def main():
    app = wx.App()
    ex = Example(None)
if __name__ == '__main__':

Output Window:

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!