環境描述:
Python 3.4
Visual Studio 2013
PTVS 2.1
想開發一個桌機小程序,作為自己使用python的第一個學習例子,
工程文件:
myWpfApplication1.py
myWpfApplication1.xaml
已將python3.4添加到了Python enviorments中去,
但是在啟動調試時,出現了以下錯誤提示:
我是剛入門學習,則進入社區還沒有C幣懸賞,請見諒,
請各位大牛不吝指教~~
附代碼
myWpfApplication1.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="myWpfApplication1" Height="300" Width="300">
<Grid>
<Button x:Name="OkButton" Content="OK" HorizontalAlignment="Left" Height="30" Margin="26,204,0,0" VerticalAlignment="Top" Width="99" Click="OkButton_Click"/>
<Button x:Name="CancelButton" Content="CancelButton" HorizontalAlignment="Left" Height="32" Margin="157,204,0,0" VerticalAlignment="Top" Width="112" Click="Button_Click"/>
<Label Content="Input your Words" HorizontalAlignment="Left" Height="27" Margin="65,10,0,0" VerticalAlignment="Top" Width="126"/>
<Label Content="You Have Input" HorizontalAlignment="Left" Height="37" Margin="65,98,0,0" VerticalAlignment="Top" Width="75"/>
<TextBox HorizontalAlignment="Left" Height="51" Margin="65,42,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="152"/>
<TextBox HorizontalAlignment="Left" Height="45" Margin="65,140,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="152"/>
</Grid>
</Window>
myWpfApplication1.py
import wpf
from System.Windows import Application, Window
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'myWpfApplication1.xaml')
def OkButton_Click(self, sender, e):
textInput=self.InputText
textOutput=self.OutputText
textOutput.Text=textInput.Text
def CancelButton_Click(self, sender, e):
textInput=self.InputText
textOutput=self.OutputText
textInput.Text=''
textOutput.Text=''
if __name__ == '__main__':
Application().Run(MyWindow())
說的很清楚,在項目屬性-調試-運行模式中修改為IronPython解釋器,現在是用的CPython
如果你沒有裝IronPython,那麼先從codeplex下載ironpython。