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.