def track_event(track_events_to, event, sequence):
    """Writes all details necessary to generate event to a file.

    Called each time an event occurs if the track_events_to variable of the CircuitEditor is not None.

    Example contents of the file:
    '<Motion>', serial = 329, state = 8, x = 643, y = 10
    '<Control-MouseWheel>', serial = 335, state = 12, x = 292, y = 239, delta = -120
    
    Parameters
    ----------
    track_events_to:    string
                        name (or path) of the folder to write to
    event:              Tkinter event
    sequence:           string
                        For example '<ButtonRelease-1>' or 'c'
    """
    to_exclude = ['<Enter>', '<Leave>']
    if sequence not in to_exclude:
        event_string = "'" + sequence + "'"
        for key, value in event.__dict__.items():
            if key in ['when', 'above', 'borderwidth', 'button', 'count',
                'data', 'detail', 'focus', 'height', 'keycode', 'keysym',
                'mode', 'override', 'place', 'root', 'rootx', 'rooty',
                'sendevent', 'serial', 'state', 'subwindow', 'warp',
                'width', 'window', 'x', 'y'
                ] or key == 'delta' and 'MouseWheel' in sequence:
                if value != '??':
                    event_string += ', ' + key + ' = ' + repr(value)
        with open(track_events_to, 'a+') as event_tracking_file:
            event_tracking_file.write(event_string + '\n')
