wxPython Replace() function in wxPython (original) (raw)
Last Updated : 11 May, 2020
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)
Parameters :
The title of the menu.
Parameter Input Type Description pos int The position of the new menu in the menu bar menu wx.Menu The menu to add. title string The menu to add.
Let’s create a window with two menu items Menu_one and Menu_two.
Code :
import
wx
class
Example(wx.Frame):
`` def
__init__(
self
,
*
args,
*
*
kw):
`` super
(Example,
self
).__init__(
*
args,
*
*
kw)
`` menubar
=
wx.MenuBar()
`` fm1
=
wx.Menu()
`` fileitem
=
fm1.Append(
20
,
"one"
)
`` fm2
=
wx.Menu()
`` fileitem2
=
fm2.Append(
20
,
"two"
)
`` menubar.Append(fm1,
'&Menu_one'
)
`` menubar.Append(fm2,
'&Menu_two'
)
`` self
.SetMenuBar(menubar)
`` self
.SetSize((
300
,
200
))
`` self
.SetTitle(
'Menu Bar'
)
def
main():
`` app
=
wx.App()
`` ex
=
Example(
None
)
`` ex.Show()
`` app.MainLoop()
if
__name__
=
=
'__main__'
:
`` main()
Window:
Now lets replace Menu_two with new_Menu.
Code for Replace :
import
wx
class
Example(wx.Frame):
`` def
__init__(
self
,
*
args,
*
*
kw):
`` super
(Example,
self
).__init__(
*
args,
*
*
kw)
`` menubar
=
wx.MenuBar()
`` fm1
=
wx.Menu()
`` fileitem
=
fm1.Append(
20
,
"one"
)
`` fm2
=
wx.Menu()
`` fileitem2
=
fm2.Append(
21
,
"two"
)
`` fm3
=
wx.Menu()
`` fileitem3
=
fm3.Append(
22
,
"new"
)
`` menubar.Append(fm1,
'&Menu_one'
)
`` menubar.Append(fm2,
'&Menu_two'
)
`` self
.SetMenuBar(menubar)
`` self
.SetSize((
300
,
200
))
`` self
.SetTitle(
'Menu Bar'
)
`` menubar.Replace(
1
, fm3,
"new_Menu"
)
def
main():
`` app
=
wx.App()
`` ex
=
Example(
None
)
`` ex.Show()
`` app.MainLoop()
if
__name__
=
=
'__main__'
:
`` main()
Output :
Similar Reads
- 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 - SetBitmap() function in wxPython 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 1 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 | 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 - 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
- Python - Create() function in wxPython In this particular article we are going to learn about Create() function present in wx.Frame class. Create function is similar to Frame() constructor of wx.Frame class. Create function is used in two-step frame construction. Syntax : wx.Frame.Create(parent, id=ID_ANY, title="", pos=DefaultPosition, 1 min read
- wxPython - SetLabel() function in wx.MenuBar Another important function in wx.MenuBar is SetLabel() function in wx.MenuBar class of wxPython. SetLabel() function is used to change the Label(title) of the menu item in menubar. It is used only after the menubar has been associated with a frame. Syntax : wx.MenuBar.SetLabel(self, id, label) Param 1 min read
- wxPython | EnableTool() function in wxPython In this article we are going to learn about EnableTool() function of wx.ToolBar class of wxPython. It is another important function in wx.Toolbar class. EnableTool() function is used to enable or disable a particular tool in Toolbar. It takes 'enable' bool parameter which is when true enable the too 2 min read
- Python - GetMenu() function in wxPython In this particular article we are going to learn about GetMenu() function of wx.MenuBar class of wxPython. GetMenu() is function in wx.MenuBar class that return wx.Menu object present in Menubar. It needs only index of menu present on menubar. Syntax : wx.MenuBar.GetMenu(self, menuindex) Parameters 1 min read
- wxPython | GetMargins() function in python In this article we are going to learn about GetMargins() function of class wx.ToolBar in wxPython. GetMargins() function returns the left/right and top/bottom margins, which are also used for inter-toolspacing. GetMargins takes no parameters. Syntax: wx.ToolBar.GetMargins(self) Parameters: No Parame 2 min read