You just need to define your input/output data as input and output arguments in your function. You can also use variables as global within your external function. After function definition:
global myvar_2 myvar_2 ....
where myvar_X are the variables used in your GUI.