wx.ToolBar edit tool label

toolbar.AddTool(toolId=100, …)

Make sure you give the tool item a unique tool id.

Note: it can be any positive number (negative numbers would make the id be random). I think 100 looks like a good id if this tool item is the left-most (i.e. the first one) on your toolbar. But if it’s the second, give the number 200… That way your code will be more readable and you’ll immediately know which tool item are you dealing with. It’s all about being organized. :wink:

toolbar.FindById(id=100).SetLabel(‘foobar’)

toolbar.Realize()

And when you want to find the tool item by its id, give the parameter id the same number that you gave to the parameter toolId of the AddTool() method.

An alternative would be to keep a reference, e.g.:
self.tb_someitem = self.toolbar.AddSimpleTool(wx.ID_ANY,
wx.Image(‘user.png’, wx.BITMAP_TYPE_PNG).ConvertToBitmap(),
‘New’, ‘Create New Document’)
self.tb_someitem.SetLabel(‘some new label’)
Werner

···

On 10/09/2012 11:20, Boštjan Mejak
wrote:

      toolbar.AddTool(toolId=100,

…)

      Make

sure you give the tool item a unique tool id.

      Note:

it can be any positive number (negative numbers would make the
id be random). I think 100 looks like a good id if this tool
item is the left-most (i.e. the first one) on your toolbar.
But if it’s the second, give the number 200… That way your
code will be more readable and you’ll immediately know which
tool item are you dealing with. It’s all about being
organized. :wink:

toolbar.FindById(id=100).SetLabel(‘foobar’)

toolbar.Realize()

      And when you

want to find the tool item by its id, give the parameter id
the same number that you gave to the parameter toolId of the
AddTool() method.

I would suggest not to use wx.AddSimpleTool(). I do suggest using wx.AddLabelTool().

Should have used that in the sample.

Anyhow he/one can use whichever of the Add???Tool methods. My point was more to keep a reference to the toolbar item instead of working with ID's.

Werner

···

On 10/09/2012 14:13, Bo�tjan Mejak wrote:

I would suggest not to use wx.AddSimpleTool(). I do suggest using wx.AddLabelTool().

Werner, you were absolutely right about keeping the reference. It’s better that catching the ID.

Hey,

Thank you guys! I’ve tried both methods, but they still didn’t work. I guess it’s a linux version problem, because everything’s fine on my windows machine.

Anyway, thanks for help!

···

On Monday, September 10, 2012 4:44:12 AM UTC-5, werner wrote:

  On 10/09/2012 11:20, Boštjan Mejak > wrote:
      toolbar.AddTool(toolId=100,

…)

      Make

sure you give the tool item a unique tool id.

      Note:

it can be any positive number (negative numbers would make the
id be random). I think 100 looks like a good id if this tool
item is the left-most (i.e. the first one) on your toolbar.
But if it’s the second, give the number 200… That way your
code will be more readable and you’ll immediately know which
tool item are you dealing with. It’s all about being
organized. :wink:

toolbar.FindById(id=100).SetLabel(‘foobar’)

toolbar.Realize()

      And when you

want to find the tool item by its id, give the parameter id
the same number that you gave to the parameter toolId of the
AddTool() method.

An alternative would be to keep a reference, e.g.:

self.tb_someitem = self.toolbar.AddSimpleTool(wx.    ID_ANY,

wx.Image(‘user.png’, wx.BITMAP_TYPE_PNG).ConvertToBitmap(),

            'New', 'Create New Document')



self.tb_someitem.SetLabel('some new label')



Werner