0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

wxPythonのwxListBoxで全選択状態を解除する

Posted at

軽く検索した限りでは見つからなかったのでメモ(目が節穴なだけかもしれない)。
ついでに全選択ボタンも記載。
ただこちらはもう少しシンプルな方法がないか調べたい。

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, title=title, pos=(100, 100), size=(400, 400))
        self.__create_widget()
        self.__do_layout()
    def __create_widget(self):
        #リストボックス
        self.columnListbox = wx.ListBox(self, wx.ID_ANY, choices=("a","b", "c"), style=wx.LB_EXTENDED | wx.LB_NEEDED_SB)

        #全選択ボタン
        self.columnSelectAllButton = wx.Button(self, wx.ID_ANY, "全て選択")
        #全選択解除ボタン
        self.columnSelectNoneButton = wx.Button(self, wx.ID_ANY, "全て解除")

        #イベント設定
        self.columnSelectAllButton.Bind(wx.EVT_BUTTON, self.OnClickSelectColumnsAllOn)
        self.columnSelectNoneButton.Bind(wx.EVT_BUTTON, self.OnClickSelectColumnsAllOff)

    def __do_layout(self):
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        #リストボックス
        sizer.Add(self.columnListbox, flag=wx.EXPAND)

        #選択状態変更ボタンs
        sizer.Add(self.columnSelectAllButton, flag=wx.EXPAND)
        sizer.Add(self.columnSelectNoneButton, flag=wx.EXPAND)

        self.SetSizer(sizer)

    #### イベント ####

    #全て選択
    def OnClickSelectColumnsAllOn(self, event):
        for c in self.columnListbox.GetItems():
            self.columnListbox.SetStringSelection(c)
        return 0
    #全て選択解除
    def OnClickSelectColumnsAllOff(self, event):
        self.columnListbox.SetSelection(-1)
        return 0

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(parent=None, ID=-1, title="test")
        self.SetTopWindow(frame)
        frame.Show()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?