Search code examples
pythonwxpython

Set toolbar button toggle state wxpython


the question looks quite basic, but I cannot manage to set the state of the toolbar toggle button to not toggled, without breaking it.

I create the toolbar toggle button using

button = toolbar.AddLabelTool(..., kind=wx.ITEM_CHECK)

Then I check the its state using

button.IsToggled()

These all work fine. The problem comes when I want to manually un-toggle the button.

I have tried

button.SetToggle(False)

which does un-toggle it but seems to break the behaviour of the button - seems to make the check above always return False.

button.IsToggled = False

and

toolbar.ToggleTool(11, False)

don't seem to work.

Any ideas ? thanks


Solution

  • toolbar.AddLabelTool(..., kind=wx.ITEM_CHECK) I believe is deprecated.
    Use toolbar.AddCheckTool(..., kind=wx.ITEM_CHECK) instead.
    Then use GetToolState() to return the state of the tool.
    Documented here Toolbar