Getting My Weather Output into labels

I’ve managed to get my code to print out the strings below onto the console, but now I am stumped how to get each string into a label.

I want it to look like a 8 day forecast, with a column per day. Here is the code I have so far:

    string = f'[{city} - 8 Days Forecast]\n'  
    for i in range(len(day)):
      if i ==0:
        string += f'\nDay {i+1} (Today \n'
      elif i ==1:
            string += f'\nDay {i+1} (Tomorrow \n'
      else:
        string += f'\nDay {i+1} \n'    
      string+= 'Daytime:'+ str(day[i])+ '°F'+"\n"
      string+= 'Feels Like:'+ str(feelslike[i])+ '°F'+"\n"
      string+= 'Night Time:'+ str(night[i])+ '°F'+"\n"
      string+= 'Morning:'+ str(morn[i])+ '°F'+"\n"
      string+= 'Evening:'+ str(eve[i])+ '°F'+"\n"
      string+= 'Minimum:'+ str(mintemp[i])+ '°F'+"\n"
      string+= 'Maximum:'+ str(maxtemp[i])+ '°F'+"\n"
      string+= 'Conditions:'+ descr[i]+ "\n"
  1. Can I isolate each day and then add a role to that label, for each line above, e.g. this?:
if i==0:
        self.label_day.text='Daytime:'+ str(day[i])+ '°F'+"\n"
  1. Or, since each of the rows will be styled differently, can you add anvil-role-somecss directly to each row on the string, if so how would I format that?

  2. Or, some other better way :grimacing:?

In the Docs, you might check out the Rich Text component. It allows (limited) styling.

For more extensive styling, you could use a Custom HTML form as a component. Use whatever HTML styling you want, and assign the resulting HTML code to the form’s html property…

1 Like

Thanks Phil, I just looked at both of those, I’m thinking probably its just as well to use the UI Elements create a framework and create a self for each element I want and use anvil-roles. I dont really think there is going to be much saving doing it another way, unless I could directly code the anvil-roles into the query.

Since it’s going to be a tabular format, there’s one more alternative that comes to mind:

The screenshots are fantastic. I plan to look into this soon, for my own purposes.

1 Like