In this wxPython tutorial let us create a check box within the previously created top-level window. The parameters within the wx.CheckBox’s class are as follows:-
parent (wx.Window) – id (wx.WindowID) – label (string) – pos (wx.Point) – size (wx.Size) – style (long) – validator (wx.Validator) – name (string) –
I am not going to use all of them but one thing to keep in mind is the size parameter is not to make the box larger or smaller but instead to make the area that surrounded the check box larger or smaller instead.
self.chkbox1 = wx.CheckBox(self.the_frame, id=2, label="Yes or No", pos=wx.Point(250, 150), size=wx.Size(width=100, height=20), style=0, name="check1")
Again I have created a function for the creation of the checkbox as follows:-
def CreateCheckBoxes(self): self.chkbox1 = wx.CheckBox(self.the_frame, id=2, label="Yes or No", pos=wx.Point(250, 150), size=wx.Size(width=100, height=20), style=0, name="check1")
Next, I will call the above function within the CreateWidgets function. The entire program is as follows:-
import wx class DerivedApp(wx.App): def OnInit(self): self.the_frame = wx.Frame(None, -1) # create the top frame self.the_frame.Show(True) return True def CreateWidgets(self): # create various widgets self.CreateButton() self.CreateCheckBoxes() def CreateButton(self): self.the_button = wx.Button(self.the_frame, id=1, label="Hello World!", pos=wx.Point(150, 150), name="Hello!") def CreateCheckBoxes(self): self.chkbox1 = wx.CheckBox(self.the_frame, id=2, label="Yes or No", pos=wx.Point(250, 150), size=wx.Size(width=100, height=20), style=0, name="check1") wxapp = DerivedApp() wxapp.CreateWidgets() # initialise all widgets wxapp.MainLoop()
Below is the outcome of the above wxPython program!