views:

155

answers:

2

I want to make a winform by C#, and add a ironpython console window in it, like a multiline textbox. So I can write python program into it to do some operations in my Winform software.

How can I do that? Thanks.

affixture:

I created a opensource project IpyIF, Ironpython Interactive Window.http://ipyiw.codeplex.com/

+2  A: 

maybe you could start here.

Quickstart: You need a string with your code from your textbox in "script". Add references from IronPython, IronPython.Modules, Microsoft.Scripting and Microsoft.Scripting.Core to your project.

ScriptRuntime runtime = IronPython.Hosting.Python.CreateRuntime();
ScriptScope scope = runtime.GetEngine("py").CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString(script,
                                  Microsoft.Scripting.SourceCodeKind.Statements);
source.Execute(scope);

a real console is included in the CodePlex-Samples

ralf.w.
I known this to call ironpython file/code/string.I want to realize the interative window.In it, I can write a line, and dir() the objects,and wirte another ...
Begtostudy
So you want something like http://www.trypython.org/ right?
jcao219
Yes,like trypython.But I want a simple realization in Winform.Where can I find the code?
Begtostudy
Here: http://code.google.com/p/trypython/source/browse/trunk/trypython/app/
jcao219
I check out the code of trypython, and I found it work with sliverlight. So I doesn't know how or can it add in WinForm.
Begtostudy
A: 

Thanks a lot. I got it by myself.

I use two TextBox, one is to input code of ironpython, another is to redirect the ironpython output.

If someone want to know how to redirection, look this: http://stackoverflow.com/questions/3055002/how-can-i-redirect-the-stdout-of-ironpython-in-c

Begtostudy