Python Forum
UnUnloading values from multiple widgets in a container
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UnUnloading values from multiple widgets in a container
#1
All,
I just started using ipywidgets and I am trying to find the ropes, so if this question has been answered previously or the documentation covers it in some way, kindly point me to that section. Essentially, here is a miniature version of the UI I am trying to develop. The question that has got me perplexed is, once I construct a UI like shown below, and the user provides their input, how do I unload the input ? I am hoping to collect values for each of the variables and trigger my logic, but the only thing I see in the documentation talks about using either interact or interactive. However I am not really sure how to use them with multiple widgets, all the examples I have come across seem to point to using them with a single widget. If anyone could point me to a good resource or provide a sample, that would be helpful.
With that classifier, here is what I am trying to do:

style = {'description_width': 'initial'}

def input_tab(tab_list, tab_names_list):
    if len(tab_list) == len(tab_names_list):
        this_tab = Tab()
        this_tab.children = tab_list
        [this_tab.set_title(i, title) for i, title in enumerate(tab_names_list)]
        return this_tab
    else:
        raise ValueError('\n Input lists should be of the same size')

def get_input_panel_num():
    input_1 = widgets.Text(value='3000', description='Input-1', style=style)
    input_2 = widgets.Dropdown(options=['yes', 'no'], description='Select one', value='yes', disabled=False, style=style)
    input_3 = widgets.IntSlider(value=0, min=0, max=1, step=1, description='Input-3', orientation='horizontal', readout=True, 
                               style=style)
    input_list_num = [input_1, input_2, input_3]
    return input_list_num

def get_input_panel_char():
    input_a = widgets.Text(value='3000', description='Input-1', style=style)
    input_b = widgets.Dropdown(options=['yes', 'no'], description='Select one', value='yes', disabled=False, style=style)
    input_c = widgets.IntSlider(value=0, min=0, max=1, step=1, description='Input-3', orientation='horizontal', readout=True, 
                               style=style)
    input_list_char = [input_a, input_b, input_c]
    return input_list_char

def create_master_tab():
    tab_names = ["tab-1", "tab-2"]
    panel_num = VBox(get_input_panel_num())
    panel_char = VBox(get_input_panel_char())
    final = input_tab(tab_list=[panel_num, panel_char], tab_names_list=tab_names)
    return final

demo = create_master_tab()
demo 
Reply
#2
Bumping for a response
Reply
#3
I'm not familiar with ipywidgets, and I suspect others lacking that knowledge is a big part of why you're not getting responses. That said, I'd have skipped over your thread even if I had the expertise, and here's why...

For anything but the most trivial of issues, and especially for issues where we don't already know the solution, we want to run the code. We want to tinker with it. We want to figure it out ourselves and then give you a helpful response, rather than going back and forth over and over hashing out small details.

The first thing I noticed with your code, after scrolling through it for about a second, was the lack of imports. I was excited at first - I'm pretty confident I can answer any Python question that doesn't include imports, unless it's really exotic. Here's the thing...
Error:
Traceback (most recent call last): File "forum.py", line 35, in <module> demo = create_master_tab() File "forum.py", line 30, in create_master_tab panel_num = VBox(get_input_panel_num()) NameError: name 'VBox' is not defined
I didn't have to run your code to know that this is the result from running it. It took a few seconds of reading code. I suppose I could Google around and try to get it working, but honestly I expect people to put in the maximum effort to help us help them before I go down a rabbit hole like that.

Anytime you're asking a question about code, you should provide full, runnable code, and if there's an error message with that code that needs to be included as well. I don't say this to shame you, but to help you - I could have (and nearly did) just skip over this. No one is going to hold it against you that you didn't know how to ask coding questions before. But if you make a habit of asking questions like this, you'll get similar answers.

tldr the best you can do at this point is make sure your code is runnable, so that people who aren't already familiar with that library can tinker with it. Providing details on how to install that library is probably worthwhile too.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Reply
#4
micseydel,
Thank you for your response. The only import that needs to be used for being able to run this is as follows:


import ipywidgets as widgets 
from ipywidgets import VBox


style = {'description_width': 'initial'}
 
def input_tab(tab_list, tab_names_list):
    if len(tab_list) == len(tab_names_list):
        this_tab = Tab()
        this_tab.children = tab_list
        [this_tab.set_title(i, title) for i, title in enumerate(tab_names_list)]
        return this_tab
    else:
        raise ValueError('\n Input lists should be of the same size')
 
def get_input_panel_num():
    input_1 = widgets.Text(value='3000', description='Input-1', style=style)
    input_2 = widgets.Dropdown(options=['yes', 'no'], description='Select one', value='yes', disabled=False, style=style)
    input_3 = widgets.IntSlider(value=0, min=0, max=1, step=1, description='Input-3', orientation='horizontal', readout=True, 
                               style=style)
    input_list_num = [input_1, input_2, input_3]
    return input_list_num
 
def get_input_panel_char():
    input_a = widgets.Text(value='3000', description='Input-1', style=style)
    input_b = widgets.Dropdown(options=['yes', 'no'], description='Select one', value='yes', disabled=False, style=style)
    input_c = widgets.IntSlider(value=0, min=0, max=1, step=1, description='Input-3', orientation='horizontal', readout=True, 
                               style=style)
    input_list_char = [input_a, input_b, input_c]
    return input_list_char
 
def create_master_tab():
    tab_names = ["tab-1", "tab-2"]
    panel_num = VBox(get_input_panel_num())
    panel_char = VBox(get_input_panel_char())
    final = input_tab(tab_list=[panel_num, panel_char], tab_names_list=tab_names)
    return final
 
demo = create_master_tab()
demo 
I unfortunately don't know how to set up tldr is, so I will have to pass on that. As for the only required packages anyone needs to install in a virtual environment to be able to run these are:
1. jupyter
2. ipywidgets
3. python
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Looking for help in Parse multiple XMLs and update key node values and generate Out.. rajesh3383 0 250 Sep-15-2020, 01:42 PM
Last Post: rajesh3383
  data from multiple Entry widgets beevee 13 823 Aug-16-2020, 12:31 PM
Last Post: deanhystad
  Assigning multiple values using tuple sivacg 2 372 Aug-06-2020, 10:29 PM
Last Post: perfringo
  How to pass multiple values from one sample to nc variable? Baloch 0 350 Jun-01-2020, 09:27 PM
Last Post: Baloch
  Inserting values from multiple lists sqlite azulu 1 550 May-24-2020, 08:40 AM
Last Post: ibreeden
  How do I install Python 3.8.1 in a RHEL 8 UBI container? DevLinuxNC 1 587 Jan-08-2020, 09:37 PM
Last Post: Clunk_Head
  Save all values to pandas of multiple classes jenniferruurs 0 465 Sep-13-2019, 12:10 PM
Last Post: jenniferruurs
  looking for a multi item container Skaperen 2 592 Apr-15-2019, 04:06 AM
Last Post: Skaperen
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 839 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Try for multiple values bluethundr 1 798 Mar-07-2019, 09:04 PM
Last Post: bluethundr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020