创建独立的可执行铁python文件

时间:2013-02-06 10:31:09

标签: python visual-studio-2010 ironpython

我在visual studio中创建了一个ironpython项目,我希望它以可执行文件的形式运行

我尝试用pyc创建可执行文件,但它不起作用(绝对没有任何东西)。

ipy.exe Tools\Scripts\pyc.py /main:"C:\<Path>\WpfApplication1.py" /target:winexe

然后我创建了一个小样本项目,看看是否有效

WpfApplication1.py

    import wpf
    from System.Windows import Application, Window


    class MyWindow(Window):
         def __init__(self):
            wpf.LoadComponent(self, 'WpfApplication1.xaml')
            self.button.Content = 'My Button'
            self.textbox.Text = 'My Text'

        def Button_Click(self, sender, e):
            self.label.Content = self.textbox.Text


    if __name__ == '__main__':
        Application().Run(MyWindow())

和xaml

    <Window 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   Title="WpfApplication1" Height="300" Width="300"> 
   <Grid>
    <TextBox x:Name="textbox" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" VerticalAlignment="Top" Width="120" />
    <Button x:Name="button" Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,41,0,0" VerticalAlignment="Top" Width="75"  Click="Button_Click"/>
    <Label x:Name="label" Height="28" HorizontalAlignment="Left" Margin="47,117,0,0" VerticalAlignment="Top" Width="182" />
</Grid>

同样的问题当我执行它时没有任何反应,我怎么调试呢?

1 个答案:

答案 0 :(得分:1)

    import clr
    clr.AddReference('IronPython.Wpf')

这就是诀窍