# 2DGrafik.py # 2DGrafik-minimiert-2.py # bearbeitet Beispiel aus der wxPython Demo import wx import colorsys from math import cos, sin, radians BASE = 80.0 # sizes used in shapes drawn below BASE2 = BASE/2 BASE4 = BASE/4 class TestPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, -1) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, evt): dc = wx.PaintDC(self) gc = self.MakeGC(dc) self.Draw(gc) def MakeGC(self, dc): try: gc = wx.GraphicsContext.Create(dc) except NotImplementedError: dc.DrawText("This build of wxPython does not support the wx.GraphicsContext " "family of classes.", 25, 25) return None return gc def Draw(self, gc): font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.BOLD) gc.SetFont(font, wx.BLACK) # wird ignoriert # make a path that contains a circle and some lines, centered at 0,0 path = gc.CreatePath() path.AddCircle(0, 0, BASE2) path.AddRectangle(BASE-BASE4, -BASE4/2, BASE+BASE2, BASE4) gc.PushState() # save current translation/scale/other state gc.Translate(60, 75) # reposition the context origin gc.SetPen(wx.Pen("navy", 1)) gc.SetBrush(wx.Brush("pink")) # gc.StrokePath(path) # nur Umrisse zeichnen # gc.FillPath(path) # nur füllen gc.DrawPath(path) # auch füllen class Fenster(wx.Frame): """ Die Klasse Fenster erzeugt einen Frame. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(100, 100), size=(300, 200)) self.panel = TestPanel(self) class MyApp(wx.App): def OnInit(self): frame = Fenster(None, "Grafik") self.SetTopWindow(frame) frame.Show(True) return True app = MyApp(redirect=False) # Parameterwert True, wenn Ausgaben in der Standard E/A angezeigt werden sollen app.MainLoop()