3

I have been having a hard time finding a straightforward solution for this. If I have a select widget, how do I actually get the value that the user clicks? I have seen 'interact' and 'observe' come up in some answers but I'm still not really sure.

For example:

    import numpy as np
    import matplotlib.pyplot as plt
    import pandas as pd
    from pandas import DataFrame
    import nba_api
    import ipywidgets as widgets
    from ipywidgets import Box
    from ipywidgets import interact

from nba_api.stats.static import teams
team_list = teams.get_teams()

team_list_df = DataFrame(team_list)
name_column = team_list_df.loc[:,'full_name']
id_column = team_list_df.loc[:,'id']
names = name_column.values
ids = id_column.values

name_id = zip(names, ids)
name_id = list(name_id)

Team1 = widgets.Select(
    options=name_id,
    value=1610612737,
    description='Team 1:',
    disabled=False
)

Team2 = widgets.Select(
    options=name_id,
    value=1610612738,
    description='Team 2:',
    disabled=False
)

box = Box(children=[Team1, Team2])

box #

I am looking to then get the values from the two widgets, to display the stats of the two teams that were selected.

Thanks in advance.

mattingham
  • 31
  • 1
  • 2

1 Answers1

5

You should be able to get the values from the widgets' value properties.

print(Team1.value)
print(Team2.value)
Jack Taylor
  • 5,588
  • 19
  • 35