pythonipyvuetifyv-btn

clicking an ipyvuetify button programmatically (part 2): Why .fire_event('click', None) does not work


I would like to know why one of the answers to this question is not working. run programmatically an ipyvuetify button

A user said: looking at the description of the v.Btn class I found this :

| ---------------------------------------------------------------------- | Methods inherited from ipyvue.VueWidget.Events: |
| fire_event(self, event, data) |
| on_event(self, event_and_modifiers, callback, remove=False) I then assume that

b.fire_event('click', None)

should do trick

But this is not the case. When doing

import ipyvuetify as v
b = v.Btn(children=['this btn'])
help(b)

indeed fire_event(self, event, data) exists but it is not called as such:

b.fire_event('click', None)

ERROR: 99 def fire_event(self, event, data): --> 100 self._event_handlers_map[event](self, event, data)

KeyError: 'click'

How can you use this function of the button?

thanks


Solution

  • You need to define the event function to call.

    def function_to_print_hello( widget, event, data):
        print('hello')
        
    b = v.Btn(children=['this btn'])
    b.on_event('click', function_to_print_hello)
    b
    
    b.fire_event('click', None)