How to open an existing window with IronPython
I'm trying to learn some IronPython to perhaps spe开发者_JAVA技巧ed up the development process time. I'm just trying to port over some simple commands and currently I'm stuck on opening an existing window. In C# I would do something like:
var about = new AboutWin();
about.Show();
Does anybody know how to go about doing this in IronPython? I'm sure it's ridiculously easy just like everything else seams to be with IronPython.
This should do the trick:
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))
See my blog for bigger example.
As far as i know you can do this the following way:
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()
E.g in your case you first need to add reference to the AboutWin and then use it the same way:
import clr
clr.AddReference(<put your assembly name here>)
from <namespace> import AboutWin
aWin = AboutWin()
aWin.Show()
精彩评论