如何在表单中插入ironpython控制台?

时间:2022-10-04 07:11:44

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.

我想通过C#进行winform,并在其中添加一个ironpython控制台窗口,就像多行文本框一样。所以我可以在其中编写python程序,在Winform软件中进行一些操作。

How can I do that? Thanks.

我怎样才能做到这一点?谢谢。

affixture:

附加物:

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

我创建了一个开源项目IpyIF,Ironpython Interactive Window.http://ipyiw.codeplex.com/

2 个解决方案

#1


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.

快速入门:您需要在“脚本”中使用文本框中的代码创建一个字符串。将IronPython,IronPython.Modules,Microsoft.Scripting和Microsoft.Scripting.Core中的引用添加到项目中。

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

CodePlex-Samples中包含一个真正的控制台

#2


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.

我使用两个TextBox,一个是输入ironpython的代码,另一个是重定向ironpython输出。

If someone want to know how to redirection, look this: How can I redirect the stdout of IronPython in C#?

如果有人想知道如何重定向,请看看:如何在C#中重定向IronPython的stdout?

#1


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.

快速入门:您需要在“脚本”中使用文本框中的代码创建一个字符串。将IronPython,IronPython.Modules,Microsoft.Scripting和Microsoft.Scripting.Core中的引用添加到项目中。

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

CodePlex-Samples中包含一个真正的控制台

#2


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.

我使用两个TextBox,一个是输入ironpython的代码,另一个是重定向ironpython输出。

If someone want to know how to redirection, look this: How can I redirect the stdout of IronPython in C#?

如果有人想知道如何重定向,请看看:如何在C#中重定向IronPython的stdout?