EllipseとRectangle

 .NET Frameworkで図形を描く方法は2種類あります。それは元々.NET Frameworkの中に組み込まれている System.Drawing名前空間にあるGraphics Device Interface plus(GDI+)を直接使用して 描くものとWPFに組み込まれている基本図形のライブラリにアクセスするSystem.Windows.Shapes名前空間にあるものです。 ここでGDI+とはPCの種類やドライバなんかに依存しないでグラフィックスを担当するWindowsのコンポーネントです。 つまり、前者はWindowsに直接描画させる方法で、後者はもう少し人にわかりやすいように翻訳されているライブラリを 使用する方法です。
 当然GDI+に直接コマンドを送ったほうが描画が早いのですが、今回はもう少しわかりやすいSystem.Windows.Shapes 名前空間にあるものをしようして図形を描画することを説明します。

 Ellipseオブジェクト

 Ellipseオブジェクトは、楕円を描画するオブジェクトです。Heightプロパティで垂直方向の直径を設定し、Width プロパティで水平方向の直径を設定します。HeightプロパティとWidthプロパティを同じ値にすると円が描かれます。 Ellipseオブジェクトの輪郭はStrokeプロパティを使用し、内部はFillプロパティで塗りつぶしを設定できます。 両プロパティとも奥が深いので、また別で説明します。
 またMarginプロパティで楕円の外側の余白の大きさを指定することができます
 XAMLファイル(ellipse1.xaml)

<Window
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Ellipse1" Height="300" Width="300">
   <Grid>
    <Ellipse Height="200" Width="50" Stroke="Black" Fill="Aquamarine" Margin="10,20,0,0"
      VerticalAlignment="Top" HorizontalAlignment="Left"/>
    <Ellipse Height="100" Width="100" Stroke="DarkOrange" Margin="80,20,0,0"
      VerticalAlignment="Top" HorizontalAlignment="Left"/>
    <Ellipse Height="100" Width="190" Stroke="Red" StrokeThickness="3" Margin="80,140,0,0"
      VerticalAlignment="Top" HorizontalAlignment="Left"/>
   </Grid>
</Window>

 スクリプトファイル

import wpf

from System.Windows import Application, Window

class MyWindow(Window):
  def __init__(self):
    wpf.LoadComponent(self, 'ellipse1.xaml')
  

if __name__ == '__main__':
  Application().Run(MyWindow())


 Rectangleオブジェクト

 Rectangleオブジェクトは、長方形や正方形を描画するオブジェクトです。図形サイズはHeightプロパティ、Widthプロパティを 使用し、周りの余白はMarginプロパティで指定します。Ellipseと同様に輪郭はStrokeプロパティを塗りつぶしにはFillプロパティを 使用します。
 Rectangleオブジェクトの角は、RadiusX、RadiusYプロパティで丸めることができます。両プロパティのDefault値は0.0で 丸くなっていませんが、曲率半径を代入すれば、丸まります。またRadiusXとRadiusYに異なる値にすると角を楕円形状に することができます。
 XAMLファイル(rectangle1.xaml)

<Window
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Rectangle1" Height="350" Width="350">
   <Grid>
     <Rectangle Width="70" Height="70" VerticalAlignment="Top" HorizontalAlignment="left"
        Margin="10,10,0,0" Stroke="Red" StrokeThickness="3" />
     <Rectangle Width="70" Height="70" VerticalAlignment="Top" HorizontalAlignment="left"
        Margin="90,10,0,0" Stroke="Green" StrokeThickness="3" RadiusX="35" RadiusY="35"/>
     <Rectangle Width="200" Height="200" VerticalAlignment="Top" HorizontalAlignment="left"
        Margin="10,90,0,0" Stroke="Gold" StrokeThickness="3" Fill="Yellow"
        RadiusX="20" RadiusY="20"/>
     <Rectangle Width="90" Height="250" VerticalAlignment="Top" HorizontalAlignment="left"
        Margin="230,30,0,0" Stroke="Navy" StrokeThickness="3" Fill="Blue"
        RadiusX="40" RadiusY="20"/>
   </Grid>
</Window>

 スクリプトファイル

import wpf

from System.Windows import Application, Window

class MyWindow(Window):
  def __init__(self):
    wpf.LoadComponent(self, 'rectangle1.xaml')
  

if __name__ == '__main__':
  Application().Run(MyWindow())


 緑のRectangleオブジェクトを使って円を描く例です。普通Ellipseオブジェクトを使いますね。(笑)