addEventListener in Python

Hey everyone,

I’m trying to change the text of a button after the audio is finished playing. The best way I believe to do it is to addEventListener, but I’m not getting it to work. Is there anyone with a successful implementation of addEventListener using Python code and not Javascript. I’ve looked at the following thread Logout User On Tab Close but I can’t figure it out without all the context.

It does help to follow the template when asking a question.
There’s a lack of context here, which will make it difficult for others to help.
You might want to fill in some details, a clone link that demonstrates the issue and/or some code snippets.

2 Likes

Here is something you can do

from anvil.js.window import document 

dom=document.getElementById('id_of_div')
dom.addEventListener('my_event',self.change_text)

def change_text(self):
   self.my_label.text='audio has finished playing'
1 Like

@stucork you are 100% correct and I will follow the post rules more closely next time :slight_smile:

@divyeshlakhotia Thank you for this suggestion, I will try it out and see if it works for my use case :slight_smile: Otherwise I’ll create a MVP app to post here.

1 Like