2

I currently am using the selectmultiple widget in ipywidgets and I'm looking for a better solution. I have 200+ countries that a user can select from and sometimes they want to SELECT ALL. Using this widget they need to click on each and every country and this is very time consuming. Does anyone have another suggestion or option that I can try. Any help would be much appreciated.

widgets.SelectMultiple(
options=['Afghanistan', 
          'Aland Islands',
          'Albania'
          'Algeria',
        #Code continues for 249 countries
         ],
value=['Afghanistan'],
#rows=10,
description='Countries',
disabled=False
 )

Thanks

Andy Jensen
  • 83
  • 2
  • 9

2 Answers2

2

You can use CMD+A in Mac to select all in the usual way, imagine CTRL+A will work for Windows too.

But if you need a widget, how about a button next to it that performs the same action?

import ipywidgets as widgets
sel = widgets.SelectMultiple(
options=['Afghanistan', 
          'Aland Islands',
          'Albania',
          'Algeria',
        #Code continues for 249 countries
         ],
value=['Afghanistan'],
#rows=10,
description='Countries',
disabled=False
 )


but = widgets.Button(description = 'Select all')

def select_all(*args):
    sel.value = sel.options

but.on_click(select_all)

display(sel)
display(but)
ac24
  • 5,325
  • 1
  • 16
  • 31
0

I have handled this by adding an 'ALL' option at the top of the list:

import ipywidgets as widgets
sel = widgets.SelectMultiple(
options=['ALL',
          'Afghanistan', 
          'Aland Islands',
          'Albania',
          'Algeria',
        #Code continues for 249 countries
         ],
value=['ALL'],
#rows=10,
description='Countries',
disabled=False
 )

This way the they will get all if they want it by default or they can choose a smaller number of items as usual.

regards

rchitect-of-info
  • 1,150
  • 1
  • 11
  • 23