1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, "Timer", wx.DefaultPosition, wx.Size(310, 150),style= wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)
self.tZero=time.time() #Récupération de tZero
self.t=time.time()-self.tZero # Temps après tZero
self.timer=wx.Timer(self, 1)
panel = wx.Panel(self, -1)
self.buttonStart = wx.BitmapButton(panel, -1, wx.Bitmap(pngLib[0]), pos=(160,93), size=(25,25))
self.Bind(wx.EVT_BUTTON, self.Start, self.buttonStart)
def Timer(self, event):
self.t=time.time() -self.tZero
# Crée un temps en seconde 4.84287779592 (0=01/01/1970)
tiTuple=time.gmtime(self.t)
# Conversion en tuple (1970, 1, 1, 0, 0, 4, 3, 1, 0)
reste=self.t-tiTuple[3]*3600.0-tiTuple[4]*60.0-tiTuple[5]*1.0
# Recupération du reste
resteS=("%.2f" % reste )[-2::]
#Affiche les dixièmes et centièmes de l'arrondi ex: 84
tt=time.strftime("%M:%S", tiTuple)+"."+resteS
self.clock.SetLabel(tt)
def Start(self, clock):
self.Bind(wx.EVT_TIMER, self.Timer, self.timer)
self.timer.Start(50)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'layout.py')
frame.SetIcon(wx.Icon('G.ico', wx.BITMAP_TYPE_ICO))
frame.Show(True)
#frame.timer.Start(50)
frame.Centre()
return True
if __name__=='__main__':
app = MyApp(0)
app.MainLoop() |
Partager