Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:46:34+00:00 2026-06-05T06:46:34+00:00

I have a wx.ListBox that I would like the user to select from as

  • 0

I have a wx.ListBox that I would like the user to select from as if they were holding down the CTRL key. So – if you click on an item that is not selected, it will be selected (without modifying other selections), and if you click on a selected item, it will be deselected (again without modifying other selections).

The code to create the listbox is:

    self.myListBox = wx.ListBox(self,
                                    -1,
                                    choices=self.keys,
                                    style =  wx.LB_HSCROLL
                                           | wx.LB_MULTIPLE
                                           | wx.LB_NEEDED_SB
                                           | wx.LB_SORT)
    self.Bind(wx.EVT_LISTBOX, self.OnSelection, self.myListBox)

Problems / questions:

  • Is there already an easy way to do this? Either wx.LB_MULTIPLE or wx.LB_EXTENDED look like they might be what I want, but I’ve tried both and it doesn’t appear to change anything. The description in the documentation is a little vague as well – what exactly is the difference between the two?

  • I know can get the id of the selected item with event.GetSelection(), but if I try to implement the above logic, i.e.:

    if self.myListBox.IsSelected(idx):
        self.myListBox.Deselect(idx)
    else:
        self.myListBox.Select(idx)
    

    the event has already fired and so it just deselects whatever was just selected. Tried calling event.Skip() before that as well, but no luck there either. Is there a way I can stop it from doing that?

  • I noticed that when dragging the mouse for multiple selections event.GetSelection() would get the correct id’s going up – i.e., 3, 2, 1, 0 – but going down it would only show the first – 0, 0, 0, 0. I’m guessing it’s just printing out the first item in the list of selections — is there a way to get the list from the event object (as opposed to calling self.myListBox.GetSelections())?

I’m running Linux and wxPython version 2.6.4.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:46:36+00:00Added an answer on June 5, 2026 at 6:46 am

    (Late answer, but it might be of use to document.)
    I ended up writing handlers for the onClick events:

    def OnSelection(self, event):
        """Simulate CTRL-click"""
        selection = self.myListBox.GetSelections()
    
        for i in selection:
            if i not in self.selectedItems:
                # add to list of selected items
                self.selectedItems.append(i)
                self.myListBox.Select(i)
            elif len(selection) == 1:
                # remove from list of selected items
                self.selectedItems.remove(i)
                self.myListBox.Deselect(i)
    
        for i in self.selectedItems:
            # actually select all the items in the list
            self.myListBox.Select(i)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF ListBox that I would like to Enable multiple selection in
I have a user control that inherits from the ListBox class and displays a
I have a listBox that I would like to carry out a method when
I have an app that has a ListBox of ListBoxes. I would like to
I currently have a listbox that has its selected item bound to a property
I have a listbox item template that contains visual states. I have DisplayStateBehaviors that
I have a new batch form where user can select books from a div
I currently have a winform with a listbox control that allows a user to
I would like to make a horizontal listbox that could be infinite scrolling (looping
I have a ObservableCollection> property that I would like to display in a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.