How to create a check box (Phoenix)

Keywords : Check box.


Introduction :

wx.CheckBox is a widget that has two states.

On and Off.

It is a box with a label.

The label can be set to the right or to the left of the box.

If the checkbox is checked, it is represented by a tick in a box.

wx.CheckBox styles :

wx.CheckBox methods

bool GetValue()

get the state of the checkbox

bool IsChecked()

determine the checkbox state

SetValue(bool state)

set the state of the checkbox

(info by Jan Bodnar / Zetcode).


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Sample one

img_sample_one.png

In our script we toggle the visibility of the title.

   1 # sample_one.py
   2 
   3 """
   4 
   5 Author : Jan Bodnar
   6 Website : zetcode.com
   7 
   8 """
   9 
  10 import wx
  11 import random
  12 
  13 # class MyCheckBox
  14 
  15 #---------------------------------------------------------------------------
  16 
  17 class MyCheckBox(wx.Frame):
  18     def __init__(self, parent, id, title):
  19         wx.Frame.__init__(self, parent, id, title, size=(300, 170))
  20 
  21         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  22 
  23         #------------
  24 
  25         panel = wx.Panel(self, -1)
  26 
  27         self.cb = wx.CheckBox(panel, -1, 'Show Title', (10, 10))
  28         self.cb.SetValue(True)
  29 
  30         #------------
  31 
  32         self.Bind(wx.EVT_CHECKBOX, self.ShowTitle, self.cb)
  33 
  34         #------------
  35 
  36         self.Centre()
  37 
  38         #------------
  39 
  40         self.Show()
  41 
  42     #-----------------------------------------------------------------------
  43 
  44     def ShowTitle(self, event):
  45         if self.cb.GetValue():
  46             self.SetTitle('Checkbox.py')
  47         else: self.SetTitle('')
  48 
  49 #---------------------------------------------------------------------------
  50 
  51 app = wx.App(0)
  52 MyCheckBox(None, -1, 'wx.CheckBox')
  53 app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Jan Bodnar (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

15/12/20 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a check box (Phoenix) (last edited 2021-01-07 16:39:50 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.