fix size of a widget

How do i fix the size of a widget.Now here below is what i have been able to make(largely due to Cody(via mailing list)).its a timer,but it has little flaws.If i resize it,i gets incremented rapidly and the timer is no longer accurate.Thus i thought of fixing widget size to prevent this.

code:

#!/usr/bin/python

import wx,time

class Nipun(wx.Frame):

def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, id, title, size=(200, 200))
    print'Program execution reached here'
    self.Bind(wx.EVT_PAINT, self.OnPaint)
    self.timer = wx.Timer(self)
    self.Bind(wx.EVT_TIMER, self.OnTimer)
    self.Centre()
    self.Show(True)
    self.i=3595
   
    print self.i
    self.timer.Start(1000)
def OnTimer(self, evt):
    print self.i
    self.Refresh() # will cause your OnPaint to be called
   
def OnPaint(self, evt):
    dc = wx.PaintDC(self)
    self.i = self.i + 1
    if self.i<59:
        string=str(0)+":"+str(0)+":"+str(self.i)
        dc.DrawText(string,100,100)
    if self.i>=60 and self.i<3600:
        string=str(0)+":"+str(self.i/60)+":"+str(self.i%60)
        dc.DrawText(string,100,100)
    if self.i>3600:
        string=str(self.i/3600)+":"+str((self.i%3600)/60)+":"+str((self.i%3600)%60)
        dc.DrawText(string,100,100)

app = wx.App()
Nipun(None, -1, ‘Nipun’)
app.MainLoop()

Could this code be added on website as it helped me understand concept of timers(thanks to Cody) and will also help other beginners as well.

nipun batra wrote:

How do i fix the size of a widget.Now here below is what i have been able to make(largely due to Cody(via mailing list)).its a timer,but it has little flaws.If i resize it,i gets incremented rapidly and the timer is no longer accurate.Thus i thought of fixing widget size to prevent this.

Yes, resizing causes paint events. So do other things so making the frame not resizable won't fix all of the problem. For example, try dragging another window over your window, or dragging your window off screen and back, and you'll get lots of paint events.

Instead, you should make your paint event handler just paint the current state of the application, not change the state itself. In other words, you should be updating self.i from the timer handler, not the paint handler.

···

--
Robin Dunn
Software Craftsman