Drop Down question

Hello,

I have a list of items in my Drop Down.
What I want is: When I click a specific item, it will do something

How can I do that ?
Can you guys tell me, I found nothing in Anvil site.

What I want to do is:

When I click a item in drop down it will run a script in my RaspberryPi

https://anvil.works/build#clone:3NJCBG2T75UPVLXG=SQBMMPDLKKDAKDEISTRVFOWH

I leave what I have for now.
Someone can help please.

you need to set the change event of the dropdown menu.
Screen Shot 2020-05-15 at 20.18.24

Screen Shot 2020-05-15 at 20.18.33

and then decide what to do on the change event.

1 Like

I know that, but when i click in one of this options, the app dont known what option i click

I try to do with some if but doesn’t work.
What I was thinking -> if i click in 4xCOM: print(“you choose 4xCOM”)
if i click in PCB1: print(“you choose PCB1”)

Simple as that, but I dont understand to much of programing oriented objects, so how do I do that ?

Have you tried?

def dropdown_change(self, **event_args):
  print(self.dropdown.selected_value)
1 Like

yes and it prints this

Its Live Object, and dont know how to get the string of this selected_value

then just do something similar to the way you set up the items I guess:

  def nome_da_placa_change(self, **event_args):
    """This method is called when an item is selected"""
    print(self.nome_da_placa.selected_value['Nome da Placa'])

2 Likes

it works :smiley:

thanks

1 Like

The way you configured the items of your drop down, you select a certain table row (the live object) of your table. Now you need to decide which column of that row you want to use.

Create a server funtion on your raspi, connect the raspi via uplink and call this function here in the change event with the value of the selected row that you want to pass to your funtion:

anvil.server.call('function_on_raspi', self.dropdown.selected_value['Nome da Plaxe'])
2 Likes