Assigning an Event from a Widget - inside a Function

Is there a better way around this?