Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get value not none
#1
Greetings,

When I run the code I get none, not the drop-down value ie: DEV, TEMP or PROD.
I am trying to exclude the none and get the value of source_.

Any assistance appreciated.

Regards,

Clive


import urllib
import urllib.parse
from urllib.parse import urlparse
import urllib.request
from   urllib.request import urlopen

def get_method_dropdown():
    methods = ['DEV', 'TEMP', 'PROD']
    method_widget = widgets.Dropdown(
        options=methods,
        value=methods[0],
        description='Env:'
    )
    display(method_widget)

#    methods_widget.on_trait_change(filter_istd_qc_by_method,'value')

    return method_widget 
		
d = widgets.Dropdown(
        options=['DEV', 'TEMP', 'PROD'], value='TEMP'
)
display(d)
#print(d.value)


output2 = widgets.Output()
#display(d, output2)

def get_value(change):
	print(change['new'])
	#print(select_variable.value)
	#clear_output()

source_ = d.observe(get_value, names='value')  ### get_value, names='value'

#print(source_)

if source_ == 'DEV':
	print("DEV = Output")
elif source_ == 'TEMP':
    print("TEMP = Output")
Reply
#2
what is widgets and where it comes from?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Apologies I forgot to add the ipywidgets

from ipywidgets import interact, widgets
from IPython.display import display

import urllib
import urllib.parse
from urllib.parse import urlparse
import urllib.request
from   urllib.request import urlopen
 
def get_method_dropdown():
    methods = ['DEV', 'TEMP', 'PROD']
    method_widget = widgets.Dropdown(
        options=methods,
        value=methods[0],
        description='Env:'
    )
    display(method_widget)
 
#    methods_widget.on_trait_change(filter_istd_qc_by_method,'value')
 
    return method_widget 
         
d = widgets.Dropdown(
        options=['DEV', 'TEMP', 'PROD'], value='TEMP'
)
display(d)
#print(d.value)
 
 
output2 = widgets.Output()
#display(d, output2)
 
def get_value(change):
    print(change['new'])
    #print(select_variable.value)
    #clear_output()
 
source_ = d.observe(get_value, names='value')  ### get_value, names='value'
 
#print(source_)
 
if source_ == 'DEV':
    print("DEV = Output")
elif source_ == 'TEMP':
    print("TEMP = Output")
Reply
#4
When I run the code I get None.

I am trying to find an on_click or on_change event to get the "new" value ie if the user chooses Dev, Test or Prod.

I would appreciate any assistance.

Thanks,

Clive
Reply
#5
I had tried if and while loops, nothing worked.

Eventually I tried if !=, this worked.
Thanks for the help


if source_ != None:
    print(source_)
This worked!!
Reply


Forum Jump:

User Panel Messages

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