Skip to content
Related Articles

Related Articles

wxPython – AddRadioTool() function in wx.ToolBar
  • Last Updated : 17 May, 2020
GeeksforGeeks - Summer Carnival Banner

In this particular article we are going to learn working of AddRadioTool() in wx.ToolBar class of wxPython. AddRadioTool() function creates a radio group such that exactly one button in the group is pressed at any moment, in other words whenever a button in the group is pressed the previously pressed button is automatically released. You should avoid having the radio groups of only one element as it would be impossible for the user to use such button.

Syntax : wx.ToolBar.AddRadioTool(self, toolId, label, bitmap1, bmpDisabled=NullBitmap, shortHelp=””, longHelp=””, clientData=None)

Parameters :

ParameterInput TypeDescription
toolidintAn integer by which the tool may be identified in subsequent operations.
labelstringThe string to be displayed with the tool.
bitmap1wx.bitmapThe primary tool bitmap.
bmpDisabledwx.bitmapThe bitmap used when the tool is disabled.
shortHelpstringThis string is used for the tools tooltip.
longHelpstringdetailed string associated with tool.
clientDataPyUserDataAn optional pointer to client data which can be retrieved later using GetToolClientData.

Return Type : wx.ToolBarToolBase

Code Example :






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):
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
  
        # add a radio tool in toolbar
        qtool = self.toolbar.AddRadioTool(12, 'right', wx.Bitmap('/Desktop/wxPython/right.png'),
                                                                        shortHelp ="Radio Tool")
        # another radio tool in radio group
        rtool = self.toolbar.AddRadioTool(13, 'right2', wx.Bitmap('/Desktop/wxPython/wrong.png'),
                                                                         shortHelp ="Radio Tool")
  
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
          
  
  
def main():
  
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()

Output :
Tick is clicked:

Cross is Clicked:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :