get value select from ipyvuetify

557 views Asked by At

It's a very simple question, but I didn't find the solution. I use ipyvuetify and I would like to get the value from Select widget. For example, if I click on "Apple" I would like to get this value in an feature.

What is the workflow to get the value from, the widget in ipyvuetify ?

import ipyvuetify as v

def on_click(widget, event, data):
        print(widget, event, data)

a = v.Col(cols=4, children=[
            v.Select(label='Functions', items=['Apple', 'Pear', 'Cherry'], outlined=True)
        ])

a.on_event('click', on_click)
a

Thank you,

2

There are 2 answers

0
Mario Buikhuizen On BEST ANSWER

This has been answered here: https://github.com/mariobuikhuizen/ipyvuetify/issues/171

import ipyvuetify as v
import ipywidgets as widgets
from ipywidgets import Layout

def on_click(widget, event, data):
    print(a.v_model)
    print(widget, event, data)

a = v.Select(
    v_model='',
    label='Functions', items=['Apple', 'Pear', 'Cherry'], outlined=False)

a.on_event('change', on_click)
a
0
Karandeep Singh On

To check and use the value of an ipyvuetify select box, you can follow these steps:

  1. Define the select box widget using the v_select function from the ipyvuetify library. Give it a unique v_model attribute to store the selected value.
import ipyvuetify as v

# Create the select box widget
select_box = v.Select(
    v_model=None,  # Unique attribute to store the selected value
    label="Select an option",
    items=["Option 1", "Option 2", "Option 3"]
)
  1. Display the select box widget using the display() function.
display(select_box)
  1. You can access the currently selected value of the select box using the v_model attribute.
selected_value = select_box.v_model
print(selected_value)
  1. To use the value of the select box, you can use it in any way you desire. For example, you can use it in a function or create conditional logic based on its value.
if selected_value == "Option 1":
    # Do something
    pass
elif selected_value == "Option 2":
    # Do something else
    pass
# ...

Remember to update the v_model attribute whenever you want to change the selected value programmatically. This can be done by assigning a new value to the v_model attribute:

select_box.v_model = "Option 2"

By updating the v_model attribute, the select box widget will automatically reflect the new selected value.