Что-то простое, как это, с wx.Timer
должно помочь вам начать.
import wx
import random # testing only
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title=""):
super(MyFrame, self).__init__(parent, id, title, size=(300,150))
self.temp = 10
self.humd = 75
# Create a simple panel using positioned text widgets
self.panel = wx.Panel(self)
temp_lbl = wx.StaticText(self, label='Temperature:', pos=(20,10))
humd_lbl = wx.StaticText(self, label='Humidity :', pos=(20,50))
self.disptemp = wx.StaticText(self, label="0", pos=(120,10))
self.disphumd = wx.StaticText(self, label="0", pos=(120,50))
self.exit = wx.Button(self, label="Stop", pos=(120,80))
# Close routine if the Close X (top right corner) is clicked
self.panel.Bind(wx.EVT_CLOSE, self.OnExit)
self.exit.Bind(wx.EVT_BUTTON, self.OnExit)
# Define a timer to run the OnTimer function every 500 micro seconds
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(500)
self.Show()
def OnTimer(self, event):
self.read_sensor()
def read_sensor(self):
#
# call your sensor routine here updating self.time and self.humd
# for testing purposes I simply increment hack them
# You probably don't have to open and close each time
# open on start| close on Exit and access with
# self.temp = ct.getTemperature()
# self.humd = ch.getHumidity()
#
self.temp = random.uniform(-20.0,50.0)
self.humd = random.uniform(10.0,100.0)
self.disptemp.SetLabel("%03.02f" % (self.temp))
self.disphumd.SetLabel("%03.02f" % (self.humd))
def OnExit(self, event):
self.timer.Stop()
self.Destroy()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None,title="Current Temperature/Humidity")
app.MainLoop()