Using icons from media columns

What I’m trying to do: I’m trying to set the icon of a button to an image from the media column of a table. I was easily able to set the source of an image to a media column but when I did the same thing with a button icon it didn’t work. I also tried setting the icon as an image source but that didn’t work as well. Please help

The documentation for the Button component describes the options available for the icon property:

The icon to display on this component. Either a URL, or a FontAwesome Icon, e.g. ‘fa:user’.

I am already aware of that. But I want to set a row from media column of table as the icon. It works well with image sources isn’t working with icons

As the docs say, the icon property needs to be a url. You can get the url for a Media object from its url property as described in the docs

I read it but I’m still a bit confused. Can you please explain further and tell me how I can do what I’m trying to do

    row = app_tables.my_table.search()[0]
    icon = row['icon'] # media object
    self.button_1.icon = icon.url # get the url for the media object

https://anvil.works/build#clone:NMIRYSIC5MTSY2PV=K6WCZCEEHCFYP6SFSXYV5GII

4 Likes

Thanks. I’ll test it tomorrow but since the solution is coming from you, I’m positive that it will work :grin:

Yes, it worked! Thanks a lot again for your constant help :blush: