wxPython – RadioGroups in wx.ToolBar

In this article we are going to learn how can we create RadioGroups in Toolbar. In Radiogroups different RadioMenus consist different RadioTools. In a particular RadioMenu if we click any RadioTool it gets chosen and other RadioTools gets unchosen automatically.
Steps:
1. We will create two Radio Tools.
2. After creating these tools a Separator is created.
3. After creating Separator we will create other two Radio tools.
4. After following these steps we will get two Radio Menus.
Syntax :
various Radio Tools{Radio Menu}
Add Separator
various Radio Tools{Radio Menu}
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() # Radio Tools ptool = self.toolbar.AddRadioTool(12, 'right', wx.Bitmap('/home/wxPython/right.png'), shortHelp ="Radio Tool") qtool = self.toolbar.AddRadioTool(13, 'right2', wx.Bitmap('/home/wxPython/wrong.png'), shortHelp ="Radio Tool") # Toolbar Separator self.toolbar.AddSeparator() # Radio Tools rtool = self.toolbar.AddRadioTool(12, 'right', wx.Bitmap('/home/wxPython/right.png'), shortHelp ="Radio Tool") stool = self.toolbar.AddRadioTool(13, 'right2', wx.Bitmap('/home/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 :
<!–
–>

wxPython – change toolbar colour wx.ToolBar

wxPython – Dynamically enable and disable tools in toolbar using button

wxPython – EnableTool() function in wx.Toolbar

wxPython – AddLabelTool() function in wx.ToolBar

wxPython – AddControl() method in wx.ToolBar

wxPython – AddRadioTool() function in wx.ToolBar

wxPython – AddSeparator() method in wx.ToolBar

wxPython | AddStretchableSpace() function in wx.ToolBar

wxPython – AddTool() function in wx.ToolBar

wxPython – ClearTools() function in wx.Toolbar



Please Login to comment…