What I’m trying to do:
I have some results coming in from colab. I want to check a string for some keywords in the database and then highlight the words that are found there while displaying this text in a textarea.
How can I do this dynamic coloring?
What I’ve tried and what’s not working:
I tried using .foreground but it doesn’t seem to work.
Code Sample:
# this is a formatted code snippet.
# paste your code between ```
class Form2(Form2Template):
def __init__(self, job, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.job = job # passed from google colab
self.PopulateText()
def PopulateText(self):
# Any code you write here will run when the form opens.
self.title.text = self.job['title']
self.location.text = self.job['location']
self.MatchKeywords()
self.src.text = self.job['via']
self.company_name.text = self.job['company_name']
def MatchKeywords(self):
colors = {0:'black', 1:'green'}
for word in self.job['description']:
self.description.foreground = colors[word in keywords]
self.description.text += word
self.description.focus()
Clone link:
share a copy of your app