first create scope here ...like this
public static ScriptScope GetModule()
{
var pyfile = "PythonFunction.py";
ScriptEngine engine = new ScriptRuntime(DynamicEngine.CreateRuntimeSetup(true)).GetEngine("IronPython");
var code = new XapVirtualFilesystem().GetFileContents(pyfile);
ScriptScope scope = engine.CreateScope();
ScriptSource script = engine.CreateScriptSourceFromString(code, pyfile);
script.Execute(scope);
return scope;
}
call this method in where you want
the python file is follow PythonFunction.py
import clr clr.AddReference("System.Windows") from System.Windows import Application
str=Application.Current.RootVisual.FindName("textBox2").Text
def hello(str): print "Hello " + str + "! Welcome to IronPython!" return "Somthing form iron Python"
Application.Current.RootVisual.FindName("textBox1").Text=hello(Application.Current.RootVisual.FindName("textBox2").Text)