Skip to content
Related Articles

Related Articles

Improve Article

Create RadioButton in frame using wxPython

  • Last Updated : 01 Aug, 2020

In this article we are going to learn about Radio Button in wxPython. A radio button item is a button which usually denotes one of several mutually exclusive options.
It has a text label next to a (usually) round button.
You can create a group of mutually-exclusive radio buttons by specifying RB_GROUP for the first in the group. The group ends when another radio button group is created, or there are no more radio buttons.

wx.RadioButton.RadioButton(parent, id = ID_ANY, label = “”, pos = DefaultPosition,
size = DefaultSize, style = 0, validator = DefaultValidator,
name = RadioButtonNameStr)


ParameterInput TypeDescription
parentwx.WindowParent window. Should not be None.
idwx.WindowIDControl identifier. A value of -1 denotes a default value.
labelstringText Label.
poswx.PointWindow position.
sizewx.WindowWindow size.
stylelongWindow style.
validatorwx.ValidatorWindow validator.
namestringWindow name.

Code Example:

# importing the module
import wx
# definition of the Example class
class Example(wx.Frame):
    # instantiating the class     
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
    # method for creation of user interface
    def InitUI(self):
        # create parent panel for radio buttons
        self.pnl = wx.Panel(self)
        # create radio button using RadioButton() constructor
        self.rb = wx.RadioButton(self.pnl, id = 1, label ="Radio", pos =(20, 20))
# definition of the main function
def main():
    # creating an App object
    app = wx.App()
    # creating an Example object
    ex = Example(None)
    # showing the Example object
    # running the App object
# driver code
if __name__ == '__main__':

Output Window:

 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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :