1

我在 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())

和xml

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

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

4

1 回答 1

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

那成功了

于 2013-02-07T07:45:01.200 回答