如何使用IronPython打开现有窗口

时间:2011-08-12 04:32:51

标签: .net wpf ironpython

我正在尝试学习一些IronPython,以加快开发过程的时间。我只是试图移植一些简单的命令,目前我仍然坚持打开一个现有的窗口。在C#中我会做类似的事情:

var about = new AboutWin();
about.Show();

有人知道如何在IronPython中这样做吗?我确信它就像IronPython的其他任何东西一样容易上瘾。

2 个答案:

答案 0 :(得分:1)

这应该可以解决问题:

import clr
clr.AddReference('PresentationFramework')
import System

from System.Windows.Markup import XamlReader
from System.Windows import Application

XAML_str = """<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="250" Height="100">
    <TextBox Text="Hello from IronPython" />
</Window>"""

app = Application()
app.Run(XamlReader.Parse(XAML_str))

请参阅我的博客bigger example

答案 1 :(得分:0)

据我所知,您可以通过以下方式执行此操作:

import clr

clr.AddReference("System.Windows.Forms")

from System.Windows.Forms import Form,Labels

myForm = Form()
myForm.Text = 'Test'
label = Label()
label.Text = 'Label Test'
myForm.Controls.Add(label)
myForm.Show()

例如,在您的情况下,您首先需要添加对AboutWin的引用,然后以相同的方式使用它:

import clr

clr.AddReference(<put your assembly name here>)

from <namespace> import AboutWin

aWin = AboutWin()
aWin.Show()