Python: SetBitmap() function in wxPython
SetBitmap() function
In the last tutorial, we have discussed about the GetLabelText() function of wx.MenuItem class which is one of the important function of this class. Now, in this tutorial, we will discuss about another important function from the wx.MenuItem class of wxPython module i.e., SetBitmap() function.
What is SetBitmap() function?
The SetBitmap() is an important function associated with the wx.MenuItem class of wxPython module. The SetBitmap() function is used to sets the bitmap for the menu item in the menu bar. It must be called before we append the given item with the menu bar associated with it.
It means if we append an item in the menu bar without providing bitmap image in it, then it may be not possible for us to setup a bitmap image later in the menu bar. But we can change or reset the bitmap image from the menu bar if we have given it initially in the function while appending.
Syntax for SetBitmap() function:
Whenever we are using the SetBitmap() function of wxMenuItem class, we have to use the syntax correctly in order to set bitmap image correctly as menu item into the menu bar of GUI. Following is the correct syntax of using the SetBitmap() function of wxPython module in our Python program:
Syntax –
wx.SetBitmap( “bmp”, “Check”)
As we can see in the above given syntax for SetBitmap() function, it takes only two parameters that we have to define properly for execution of SetBitmap() function successfully.
Parameters:
Following are the description of the parameters that must be given in the SetBitmap() function:
- bmp: The bmp is the bitmap image given in the SetBitmap() function. This parameter is used to set the bitmap image for the menu bar. It will add the bitmap image as a menu item in the menu bar.
- checked: The checked is the value given in the SetBitmap() function. The bool value true will be used to check the image given and false value will be assigned to uncheck the image given in the function. It works like enabling or disabling the given image in the menu item of menu bar.