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: