Yui
Yui

Reputation: 103

creating standalone executable iron python file

I created a ironpython project in visual studio and I want it to run as executable

I tried creating the executable with pyc but it doesn't work(It does absolutly nothing).

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

then i created a small sample project to see if that works

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

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

same problem nothing happens when i execute it, how do I even debug that?

Upvotes: 1

Views: 1698

Answers (1)

Yui
Yui

Reputation: 103

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

that did the trick

Upvotes: 1

Related Questions