ich würd gern eine Linie auf ein Panel zeichnen lassen mit dem wxPaintDC Objekt und der DrawLine Funktion...wenn ich es so wie im folgenden Code mache, habe ich aber 100% Systemauslastung und kann das Programm nicht mehr beenden. Weiß jemand Hilfe? Vielen Dank
Code: Alles auswählen
from wxPython.wx import *
import time
import wx, random
VERSION = 'Rahmen, 1.0.20040223'
class CMyFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(640, 480))
# falls der Windowmanager das Fenster schliesst
EVT_CLOSE(self, self.OnBeenden)
#--------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------
#Panel
self.panel = wxPanel(self, -1)
#Handler fürs zeichnen lassen
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.lines = self.makeRandomLines(2, 400, 300)
def makeRandomLines(self, num, w, h):
pnts = []
for i in range(num):
x1 = random.randint(0, w)
y1 = random.randint(0, h)
x2 = random.randint(0, w)
y2 = random.randint(0, h)
pnts.append( (x1,y1, x2,y2) )
return pnts
def zeichnen(self, dc):
dc.BeginDrawing()
dc.SetPen(wx.Pen("BLACK", 2))
dc.DrawLineList(self.lines)
dc.DrawLineList(self.lines, wx.Pen("RED", 2))
dc.EndDrawing()
def OnPaint(self, event):
dc = wxPaintDC(self.panel)
dc.Clear()
self.zeichnen(dc)
#--------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------
def OnBeenden(self, event):
print 'beenden'
self.Destroy()
class CMyApp(wxApp):
def OnInit(self):
frame = CMyFrame(None, -1, VERSION)
frame.Show(True)
return true
if __name__ == '__main__':
app = CMyApp(0)
app.MainLoop()