I would like to draw some simple drawings (lines, circles, etc.) on panel in wxpython. I modified an example code I found somewhere. It works fine, but just until I minimize the window or switch to another window and back. Then it starts repainting in infinite loop.
Should this even happen? If not, is there any way to prevent the infinite loop?
One solution I found was using wx.Timer, but it just caused same loop with adjustable intervals.
import math
import wx
class DrawPanel(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,title='Drawing on panel')
self.Bind(wx.EVT_PAINT,self.OnDraw)
def OnDraw(self,event=None):
self.dc = wx.PaintDC(self)
self.dc.Clear()
self.dc.SetPen(wx.Pen(wx.BLACK,1.5))
i0 = 1
for i in range(2,1000,1):
i = i/10.0
self.dc.DrawLine(i0,200*math.sin(i0/10)+200,
i,200*math.sin(i/10)+200)
i0 = i
if __name__ == '__main__':
aplication = wx.App()
ram = DrawPanel(parent=None)
ram.Show()
aplication.MainLoop()
In the function
OnDrawcreate local variabledcinstead of using attribute (dcinstead ofself.dc).