wxPython SetBitmap() function in wxPython (original) (raw)
Last Updated : 09 Jun, 2020
In this article we are going we are going to learn about SetBitmap() function associated with wx.MenuItem class of wxPython. SetBitmap() sets the bitmap for the menu item. SetBitmap must be called before the item is appended to the menu, i.e. appending the item without a bitmap and setting one later is not guaranteed to work. But the bitmap can be changed or reset later if it had been set up initially.
Syntax:
wx.SetBitmap
Parameters:
Parameter Input Type Description bmp wx.Bitmap Bitmap to set for menu item. checked bool True to check and False for uncheck.
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)
`` self
.menubar
=
wx.MenuBar()
`` self
.fileMenu
=
wx.Menu()
`` self
.item
=
wx.MenuItem(
self
.fileMenu,
1
,
'&Radio'
, helpString
=
"Check Help"
)
`` self
.item.SetBitmap(bmp
=
wx.Bitmap(
'right.png'
), checked
=
True
)
`` self
.fileMenu.Append(
self
.item)
`` self
.menubar.Append(
self
.fileMenu,
'&File'
)
`` self
.SetMenuBar(
self
.menubar)
`` self
.SetSize((
350
,
250
))
`` self
.SetTitle(
'Icons and shortcuts'
)
`` self
.Centre()
def
main():
`` app
=
wx.App()
`` ex
=
Example(
None
)
`` ex.Show()
`` app.MainLoop()
if
__name__
=
=
'__main__'
:
`` main()
Output Window:
Similar Reads
- wxPython - Replace() function in wxPython Another function in wx.MenuBar class is Replace() function. If we ever want to replace a menu from menubar we use Replace() function. It takes three main parameters that is position of menu we want to replace, menu we want to add, title of new menu. Syntax : wx.MenuBar.Replace(self, pos, menu, title 2 min read
- Python - Move() function in wxPython In this particular article we will learn, how can we move our window to a particular point. This can be achieved using Move() function in wx.Window class of wxPython. Move() takes x and y points to move window to a particularx, y point. Syntax : wx.Move(self, x, y, flags=SIZE_USE_EXISTING) Parameter 1 min read
- wxPython | InsertSimpleTool() function in python In this article we are going to learn about InsertSimpleTool() function associated with wx.ToolBar class of wxPython. InsertSimpleTool() function is another old style method to insert a tool in the toolbar. InsertSimpleTool() function inserts the tool with the specified attributes into the toolbar a 2 min read
- wxPython - SetBitmaps() function in wx.MenuItem In this article we are going to learn about SetBitmaps() function associated with the wx.MenuItem class of wxPython. SetBitmaps() function Sets the checked/unchecked bitmaps for the menu item. The first bitmap is also used as the single bitmap for uncheckable menu items. It takes two bitmaps as para 1 min read
- wxPython | GetToolBitmapSize() function in python In this article we are going to learn about GetToolBitmapSize() function of wxPython. GetToolBitmapSize() returns the size of bitmap that a toolbar expects to have. The default bitmap size is platform-dependent: for example, it is 16x15 for MSW and 24x24 for GTK. This size does not necessarily indic 2 min read
- wxPython | Exit() function in wxPython In this article we are going to learn about wx.Exit() which is a inbuilt parent function present in wxPython.Exit() function exits application after calling wx.App.OnExit . Should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to termin 1 min read
- wxPython - SetBitmapPosition() function in wx.Button In this article we are going to learn about SetBitmapPosition() function associated with wx.Button class of wxPython. SetBitmapPosition() function is used to set the direction of bitmap where you want to set. Directions: 1. wx.LEFT 2. wx.RIGHT 3. wx.BOTTOM 3. wx.TOP Syntax: wx.Button.SetBitmapPositi 1 min read
- wxPython - Wrap() function in wx.StaticText() In this article we are going to learn about Wrap() function associated with wx.StaticText class of wxPython. Wrap() functions wraps the controls label so that each of its lines becomes at most width pixels wide if possible (the lines are broken at words boundaries so it might not be the case if word 1 min read
- wxPython - GetLabelText() function in wxPython In this article we are going to learn about GetLabelText() function associated with wx.MenuItem class of wxPython. GetLabelText() function strips all accelerator characters and mnemonics from the given text. For Example: wx.MenuItem.GetLabelfromText("&Hello\tCtrl-h") will return just "Hello" . T 1 min read
- wxPython - GetBatteryState() function in wxPython In this article we are going to learn about wx.GetBatteryState() which is a inbuilt parent function present in wxPython. GetBatteryState() returns battery state as one of BATTERY_NORMAL_STATE, BATTERY_LOW_STATE, BATTERY_CRITICAL_STATE, BATTERY_SHUTDOWN_STATE or BATTERY_UNKNOWN_STATE . BATTERY_UNKNOW 1 min read