Wednesday, May 6, 2026
HomeLanguageswxPython – GetBitmap() function in wx.Button

wxPython – GetBitmap() function in wx.Button

In this article we are going to learn about GetBitmap() function associated with wx.Button class of wxPython. GetBitmap() function is simply used to return the bitmap shown by the button.

The returned bitmap may be invalid only if the button doesn’t show any images

Syntax: wx.Button.GetBitmap(self)

Parameters: No parameters in GetBitmap() function.

Return Type: wx.Bitmap

Code Example:




import wx
  
  
class Example(wx.Frame):
  
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
        self.InitUI()
  
    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)
        self.st = wx.Button(self.pnl, id = 1, label ="Button", pos =(20, 20),
                                          size =(100, 30),  name ="button")
          
        # set bmp as bitmap for button
        self.st.SetBitmap(bmp)
  
        # get wx.Bitmap object
        bmap = self.st.GetBitmap()
  
        # print depth of bitmap
        print(bmp.Depth)
  
        self.SetSize((350, 250))
        self.SetTitle('wx.Button')
        self.Centre()
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Console Output:

32

Output Window:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6890 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12105 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6962 POSTS0 COMMENTS