【wxpython】CheckListBoxでチェックする方法
■このノートの前提
wxpythonでCheckListBoxを配置できている必要があります。
■わかること
wxpythonのCheckListBoxに☑をセットできるようになります。
■実践
結論から申しますと、チェックしたいチェックボックスのインデックス(配列番号)を配列で準備し、CheckListBoxに渡すことになります。
ここで使用する関数は「SetCheckedItems」です。
# sample1
# [list_chkbox]が今回対象のwx.CheckListBoxオブジェクトです
# 前提:list_chkboxにはすでに幾つかの項目が用意されていること
indexes = [] # チェック対象の配列
# lists チェックボックスのリスト
for y, item in enumerate(lists):
indexes.append(y)
# チェックしたいイデックスを格納した配列を渡す
list_chkbox.SetCheckedItems(indexes)
![キャプチャ](https://assets.st-note.com/production/uploads/images/28283720/picture_pc_a0ab4fdd8a61f4aba9019e6d411c44da.png)
wxpythonの公式は初心者には分かりにくいです。全英語表記です。
SetCheckedItems(self, indexes)
SetCheckedItems(indexes)
#Sets the checked state of items if the index of the item
# is found in the indexes sequence.
最初は引数のindexesが何のことだか分らなかったです。
sample1で記載した内容では「indexes」の配列に
リストボックスに合わせたインデックスをすべて持たせているので、
リストの全項目にチェックが入ることになります。
以上です。