Python WPF在VS中无法输出

2024-09-19 20:56:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我在visualstudio中使用ironpython制作了一个非常简单的GUI。你知道吗

一旦我点击按钮,我想看到一个打印“你好世界”。你知道吗

但是,代码不会给出任何打印输出。你知道吗

.py文件:

import wpf

from System.Windows import Application, Window

class MyWindow(Window):
    def __init__(self):
        self.ui = wpf.LoadComponent(self, 'WpfApplication2.xaml')

    def Button_Click(self, sender, e):
        print('hello world')


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="WpfApplication2" Height="300" Width="300"> 
       <Grid>
        <Button x:Name="Button" Content="Button" HorizontalAlignment="Left" Height="86" Margin="47,68,0,0" VerticalAlignment="Top" Width="184" Click="Button_Click"/>
    </Grid>
</Window> 

更新:

它只在im不在项目的文件夹中并且我选择构建当前文件时工作。知道为什么吗? enter image description here

谢谢你。你知道吗


Tags: 文件importselfhttpapplicationdefbuttonwindow