开发者

How can I insert an ironpython console into my form?

开发者 https://www.devze.com 2023-01-03 10:40 出处:网络
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.

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 Interacti开发者_如何学运维ve Window.http://ipyiw.codeplex.com/


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


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#?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号