wxPython | GetToolByPos() function in python (original) (raw)
Last Updated : 18 Aug, 2020
In this article we are going to learn about GetToolByPos() function present in wx.ToolBar class of wxPython. GetToolByPos() function is used to simply return a pointer to the tool at specific position.
GetToolByPos() function takes a single parameter that is pos(position of tool).
Syntax:
wx.ToolBar.GetToolByPos(self, pos)
Parameters :
Parameter Input Type Description pos int position of tool starting from 0. Return Type:
wx.ToolBarToolBase
Code Example 1:
import
wx
class
Example(wx.Frame):
`` global
count
`` count
=
0
;
`` def
__init__(
self
,
*
args,
*
*
kwargs):
`` super
(Example,
self
).__init__(
*
args,
*
*
kwargs)
`` self
.InitUI()
`` def
InitUI(
self
):
`` self
.locale
=
wx.Locale(wx.LANGUAGE_ENGLISH)
`` pnl
=
wx.Panel(
self
)
`` self
.toolbar
=
self
.CreateToolBar()
`` self
.toolbar.SetMargins(
10
,
10
)
`` rtool
=
self
.toolbar.AddTool(
13
,
'Toolone'
, wx.Bitmap(
'wrong.png'
), shortHelp
=
"Simple Tool2"
)
`` stool
=
self
.toolbar.AddTool(
14
,
'Tooltwo'
, wx.Bitmap(
'wrong.png'
), shortHelp
=
"Simple Tool"
)
`` self
.toolbar.Realize()
`` self
.SetSize((
350
,
250
))
`` self
.SetTitle(
'Control'
)
`` self
.Centre()
`` obj
=
self
.toolbar.GetToolByPos(
1
)
`` print
(obj.GetLabel())
def
main():
`` app
=
wx.App()
`` ex
=
Example(
None
)
`` ex.Show()
`` app.MainLoop()
if
__name__
=
=
'__main__'
:
`` main()
Output:
Tooltwo
Code Example 2:
import
wx
class
Example(wx.Frame):
`` global
count
`` count
=
0
;
`` def
__init__(
self
,
*
args,
*
*
kwargs):
`` super
(Example,
self
).__init__(
*
args,
*
*
kwargs)
`` self
.InitUI()
`` def
InitUI(
self
):
`` self
.locale
=
wx.Locale(wx.LANGUAGE_ENGLISH)
`` pnl
=
wx.Panel(
self
)
`` self
.toolbar
=
self
.CreateToolBar()
`` self
.toolbar.SetMargins(
10
,
10
)
`` rtool
=
self
.toolbar.AddTool(
13
,
'Toolone'
, wx.Bitmap(
'wrong.png'
), shortHelp
=
"Simple Tool2"
)
`` stool
=
self
.toolbar.AddTool(
14
,
'Tooltwo'
, wx.Bitmap(
'wrong.png'
), shortHelp
=
"Simple Tool"
)
`` self
.toolbar.Realize()
`` self
.SetSize((
350
,
250
))
`` self
.SetTitle(
'Control'
)
`` self
.Centre()
`` obj
=
self
.toolbar.GetToolByPos(
0
)
`` print
(obj.GetLabel())
def
main():
`` app
=
wx.App()
`` ex
=
Example(
None
)
`` ex.Show()
`` app.MainLoop()
if
__name__
=
=
'__main__'
:
`` main()
Output:
Toolone
Similar Reads
- wxPython | GetToolPos() function in python In this article we are going to learn about GetToolPos() function associated with wx.ToolBar class of wxPython. GetToolPos() function simply returns the tool position in the toolbar, or NOT_FOUND if the tool is not found. GetToolPos() function only takes toolId(ID of the tool in question, as passed 2 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 | GetToolEnabled() function in python In this article we are going to learn about GetToolEnabled() function present in class wx.ToolBar of wxPython. GetToolEnabled() function simply returns a pointer to the tool at particular position. It takes only single argument that is pos(position of tool starting from 0). Syntax : wx.ToolBar.GetTo 2 min read
- wxPython | GetToolPacking() function in python In this article we are going to learn about GetToolPacking() function associated with wx.ToolBar class of wxPython. GetToolPacking() function simply returns the value used for packing tools.The packing is used for spacing in the vertical direction if the toolbar is horizontal, and for spacing in the 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
- wxPython | GetToolLongHelp() function with python In this article we are going to learn about GetToolLongHelp() function present in wx.ToolBar class of wxPython. GetToolLongHelp() function returns the long help for the given tool. It takes only one argument that is toolid( ID of the tool in question, as passed to AddTool ). Syntax: wx.GetToolLongHe 2 min read
- wxPython | GetToolState() function in wx.ToolBar In this article we are going to learn about GetToolState() function associated with wx.ToolBar class of wxPython. GetToolState() function gets the on/off state of a toggle tool. It returns True if the tool is toggled on, False otherwise. It takes only toolId as a parameter to identify Tool. Syntax: 2 min read
- wxPython | GetToolsCount() function in wx.ToolBar In this article we are going to learn about GetToolsCount() function associated with class wx.ToolBar in wxPython. GetToolsCount() function simply returns the number of tools in the toolbar. GetToolsCount() function takes no parameters. Syntax : wx.ToolBar.GetToolsCount(self) Parameters : No paramet 2 min read
- Python - CreateToolBar() in wxPython In this article we will learn how can we add a toolbar in a frame. A toolbar in a gui application provides quick access to various important tools. We can create toolbar using CreateToolBar() function in wx.Frame class of wxPython. Syntax : wx.Frame.CreateToolBar(self, style=TB_DEFAULT_STYLE, id=ID_ 1 min read