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) 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 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.BOLD) gc.SetFont(font, wx.BLACK) # wird ignoriert # make a path path = gc.CreatePath() path.MoveToPoint(-BASE2, 0) path.AddLineToPoint(0, 0) path.AddLineToPoint(BASE4, BASE4) path.MoveToPoint(0, 0) path.AddLineToPoint(BASE4, -BASE4) # Now use that path to demonstrate various capbilites of the grpahics context gc.PushState() # save current translation/scale/other state gc.Translate(10, 10) # reposition the context origin gc.SetPen(wx.Pen("navy", 1)) for anzahl in range(5): self.TeilStrecke(gc, path, 10*BASE/(10+anzahl), 5./(5+anzahl), anzahl*10) gc.PopState() # restore saved state gc.PushState() # save it again def TeilStrecke(self, gc, path, laenge, faktor, winkel): gc.Scale(faktor, faktor) # verkleinern mit Faktor 80% gc.Translate(laenge,laenge) gc.Rotate(radians(winkel)) gc.DrawPath(path) class MyFrame(wx.Frame): """ Grafik-Fenster. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(50, 50), size=(600, 600)) # Create the menubar menuBar = wx.MenuBar() # and a menu menu = wx.Menu() menu2 =wx.Menu() # add an item to the menu, using \tKeyName automatically # creates an accelerator, the third param is some help text # that will show up in the statusbar menu.Append(wx.ID_EXIT, "B&eenden\tAlt-X", "Schliessen der Anwendung") # bind the menu event to an event handler self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT) # and put the menu on the menubar menuBar.Append(menu, "&Datei") menuBar.Append(menu2, "&Hilfe") self.SetMenuBar(menuBar) self.CreateStatusBar() # Now create the Panel to put the other controls on. panel = TestPanel(self) def OnTimeToClose(self, evt): """Event handler for the Menu - click.""" print( "ENDE!" ) self.Close() class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, "Grafik") self.SetTopWindow(frame) frame.Show(True) return True app = MyApp(redirect=False) app.MainLoop()