Skip to content
Related Articles

Related Articles

Improve Article

wxPython – Add Image in Button

  • Last Updated : 24 Jun, 2020
Geek Week

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)


ParameterInput TypeDescription
bitmapwx.BitmapBitmap 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:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up