Python GUI Creating CheckBox in wxPython

In this Python GUI article i want to show Creating CheckBox in wxPython. so checkbox is a labelled box which by default is either on (checkmark is visible) or off (no checkmark).

 

 

This class supports the following styles:

  • wx.CHK_2STATE: Create a 2-state checkbox. This is the default.
  • wx.CHK_3STATE: Create a 3-state checkbox. Not implemented in GTK1.
  • wx.CHK_ALLOW_3RD_STATE_FOR_USER: By default a user can’t set a 3-state checkbox to the third state. It can only be done from code. Using this flags allows the user to set the checkbox to the third state by clicking.
  • wx.ALIGN_RIGHT: Makes the text appear on the left of the checkbox.

 

 

 

 

Python GUI Creating CheckBox in wxPython

Let’s create our example, so this is the complete code for Python GUI Creating CheckBox in wxPython

 

 

 

This is our MyFrame class that inherits from wx.Frame. and it is our top level window. and also we create the object of MyPanel in here.

 

 

 

 

This is MyPanel class that inherits from wx.Panel and we are going to create our layouts with CheckBox in this MyPanel class. because MyPanel class is a container for all widgets in wxPython.

 

 

 

 

So this is the code for creating of three CheckBoxes and also we are going to bind an event handler in these CheckBoxes.

 

 

 

We also needs a StaticText for this

 

 

 

This is event binding

 

 

 

And this is the method that we want to bind with our CheckBoxes.

 

 

 

 

So the last class is MyApp class that inherits from wx.App. the OnInit() method is where you will most often create frame subclass objects.

and start our main loop.That’s it. Once the application’s main event loop processing takes over, control passes to wxPython. Unlike procedural programs, a wxPython GUI program primarily responds to the events taking place around it, mostly determined by a human user clicking with a mouse and typing at the keyboard. When all the frames in an application have been closed, the app.MainLoop() method will return and the program will exit.

 

 

 

 

Run the code and this will be the result

Python GUI Creating CheckBox in wxPython
Python GUI Creating CheckBox in wxPython

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×