如何从WPF和Python中的代码创建按钮?

2024-09-19 20:50:08 发布

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

我需要建立多个按钮,但我不能显示任何按钮!这是我用IronPython2.7编写的WPF应用程序代码。。在

我试过两种不同的方法Grid.Children.Add(按钮)“如果没有这个,什么都不会显示。。在

XAML:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
        x:Name="NewWindow" Height="564.22" Width="993.2">

    <Grid x:Name="grid" Margin="0,0,75.2,92.4">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>  
        <Button Content="Create a Button from code" HorizontalAlignment="Left"
         Margin="712,418,0,0" VerticalAlignment="Top" Width="167" Height="61"
         Click="CreateButtons_Click"/>     
    </Grid>
</Window>

代码:

^{pr2}$

显示错误:

expected UIElement, got Button

如果我跳过那个错误并删除行self.grid.Children.添加(self.myButton),它不会得到错误,但也不会显示任何按钮。在

如何通过python代码在那里显示我的按钮?(python和wpf的新成员)


Tags: comhttp错误buttonformswindow按钮system