3

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/

Begtostudy
  • 1,374
  • 4
  • 13
  • 28

2 Answers2

2

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.
  • 1,676
  • 1
  • 24
  • 34
  • 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 Jun 16 '10 at 12:32
  • Yes,like trypython. But I want a simple realization in Winform. Where can I find the code? – Begtostudy Jun 16 '10 at 16:00
  • 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 Jun 17 '10 at 02:31
0

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: How can I redirect the stdout of IronPython in C#?

Community
  • 1
  • 1
Begtostudy
  • 1,374
  • 4
  • 13
  • 28