0

我正在尝试for steps in []使用 IronPython WPF 应用程序中的 Polyline() 创建一个非常简单的循环示例。循环的每次迭代都应该绘制不同的颜色,但是 Brushes 实现了一组预定义的 System.Windows.Media.SolidColorBrush 对象。我不知道如何交换Red我的steps变量。

def polylineShape(self):

    x = self.myCanvas.Width/2
    y = self.myCanvas.Height/2
    polyline = Polyline()
    polyline.StrokeThickness = 5


    for steps in ['Red','Blue','Green','Black']:
        x = x
        y = x            
        polyline.Points.Add(Point(x,y))
        x = x + 40
        polyline.Points.Add(Point(x,y))
        polyline.Stroke = Brushes.Red        #change colour on iteration

    self.myCanvas.Children.Add(polyline)
4

1 回答 1

0

我通过反复试验创建了一个解决方案,我无法弄清楚如何将颜色直接传递给 Brushes 类型。

def polylineShape(self):
    x = 0
    y = 0

    for steps in [Brushes.SteelBlue, Brushes.DarkOrange, Brushes.DarkSeaGreen, Brushes.Honeydew]:
        polyline = Polyline()                                           
        polyline.StrokeThickness = self.myCanvas.Height/4               
        x = 0                                                           
        y = y + self.myCanvas.Height/4                                  
        polyline.Points.Add(Point(x,y))                                 

        x = self.myCanvas.Width                                         
        polyline.Points.Add(Point(x,y))                                 

        polyline.Stroke = steps                                         

        self.myCanvas.Children.Add(polyline)
于 2015-10-30T00:53:07.817 回答