Evento#

Inicializando la clase de evento#

Un evento se crea utilizando el siguiente constructor:

Event(callback, arg)

Este constructor utiliza dos parámetros:

Parámetro

Descripción

callback

Opcional. Una función previamente definida que se llamará como un hilo cuando se transmita el evento.

arg

Opcional. Una tupla que se utiliza para pasar argumentos a la función de devolución de llamada de evento.

# Define the function broadcasted_event().
def broadcasted_event():
    brain.screen.print("Event was broadcast")
# Construct an Event "event" with the
# Event class.
event = Event(broadcasted_event)

This event object will be used in all subsequent examples throughout this API documentation when referring to Event class methods.

Métodos de clase#

set()#

The set(callback, arg) method sets a new callback and arguments for the event.

Parámetros

Descripción

llamar de vuelta

La nueva función de devolución de llamada que se llamará cuando se active el evento.

arg

Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada.

Devoluciones: Ninguna.

# Define a function event_occured()
def event_occured():
    brain.screen.print("event occured")

# Set the event to run event_occured() instead of print()
# when the event is broadcast.
event.set(event_occured)

broadcast()#

The broadcast() method broadcasts the event and causes all registered callback functions to run.

Devoluciones: Ninguna.

# Broadcast event and run print().
event.broadcast()

broadcast_and_wait()#

The broadcast_and_wait() method broadcasts the event, causes all registered callback functions to run, and waits until all callback functions have been completed.

Devoluciones: Ninguna.

# Broadcast event and wait for completion.
event.broadcast_and_wait()