2016-10-26 15 views
0

静的テキストを1つだけ更新する方法を知っているので、複数の静的テキストを動的に更新したい。複数のwxpython静的テキストを動的に更新する方法は?

以下

私のコードです:

import os 
import time 
import datetime 

current_time = datetime.datetime.strftime(datetime.datetime.now(), '%d- %m-%Y %H:%M:%S') 
try: 
    import wx 
except ImportError: 
    raise ImportError, "The wxPython module is required to run this program." 

class simpleapp_wx(wx.Frame): 
    def __init__(self,parent,id,title): 
     wx.Frame.__init__(self,parent,id,title, size =(500,300)) 
     self.SetBackgroundColour(wx.BLUE) 
     self.parent = parent 
     self.initialize() 

    def initialize(self): 
     sizer = wx.GridBagSizer() 
     font = wx.Font(20, wx.DECORATIVE, wx.ITALIC, wx.NORMAL) 
     self.SetFont(font) 


     self.label = wx.StaticText(self,-1,label=u'Time Updated - 1: {}'.format(current_time)) 
     self.label.SetBackgroundColour(wx.BLUE) 
     self.label.SetForegroundColour(wx.WHITE) 
     sizer.Add(self.label, (4,0),(1,5),wx.EXPAND) 
     self.on_timer() 

     self.SetSizer(sizer) 
     self.Show(True) 

    def on_timer(self): 
     current_time = datetime.datetime.strftime(datetime.datetime.now(), '%d-%m-%Y %H:%M:%S') 
     self.label.SetLabel(label=u'Time Updated -1 : {}'.format(current_time)) 
     wx.CallLater(1000, self.on_timer) 

if __name__ == "__main__": 
    app = wx.App() 
    frame = simpleapp_wx(None,-1,'Rain Sensor') 
    app.MainLoop() 

私は同じクラスの別の静的なテキストを追加し、別のCallLaterを作成しようとしましたが、それは最後の静的テキストを更新...

答えて

0

コード以下のwin7のx86のは、私はちょうど、別のラベルlabel2を作成サイザーでそれを入れて、あのを作成しているwxPythonを3.0.2

import os 
import time 
import datetime 

current_time = datetime.datetime.strftime(datetime.datetime.now(), '%d- %m-%Y %H:%M:%S') 
try: 
    import wx 
except ImportError: 
    raise ImportError, "The wxPython module is required to run this program." 

class simpleapp_wx(wx.Frame): 
    def __init__(self, parent, id, title): 
     wx.Frame.__init__(self, parent, id, title, size=(500, 300)) 
     self.SetBackgroundColour(wx.BLUE) 
     self.parent = parent 
     self.initialize() 

    def initialize(self): 
     sizer = wx.GridBagSizer() 
     font = wx.Font(20, wx.DECORATIVE, wx.ITALIC, wx.NORMAL) 
     self.SetFont(font) 

     self.label = wx.StaticText(self, -1, label=u'Time Updated - 1: {}'.format(current_time)) 
     self.label2 = wx.StaticText(self, -1, label=u'Time Updated - 2: {}'.format(current_time)) 
     self.label.SetBackgroundColour(wx.BLUE) 
     self.label.SetForegroundColour(wx.WHITE) 
     self.label.SetBackgroundColour(wx.BLUE) 
     self.label2.SetForegroundColour(wx.WHITE) 
     sizer.Add(self.label, (4, 0), (1, 5), wx.EXPAND) 
     sizer.Add(self.label2, (5, 0), (1, 5), wx.EXPAND) 
     self.on_timer() 
     self.on_timer2() 

     self.SetSizer(sizer) 
     self.Show(True) 

    def on_timer(self): 
     current_time = datetime.datetime.strftime(datetime.datetime.now(), '%d-%m-%Y %H:%M:%S') 
     self.label.SetLabel(label=u'Time Updated -1 : {}'.format(current_time)) 
     wx.CallLater(1000, self.on_timer) 

    def on_timer2(self): 
     current_time = datetime.datetime.strftime(datetime.datetime.now(), '%d-%m-%Y %H:%M:%S') 
     self.label2.SetLabel(label=u'Time Updated -2 : {}'.format(current_time)) 
     wx.CallLater(1000, self.on_timer2) 

if __name__ == "__main__": 
    app = wx.App() 
    frame = simpleapp_wx(None, -1, 'Rain Sensor') 
    app.MainLoop() 

、私のマシン上でうまく動作しますthe on_timer2メソッドと呼ばれるwx.CallLater

+0

私はまだwxpythonには新しく感謝します。今私はこのサンプルコードから私のプロジェクトを更新する方法を知っています.... – anubismmt

+0

@anubismmtこれがあなたの質問に答えるならば、あなたはそれを受け入れ、そして/またはそれを有益なものとして投票するべきです。 –

+0

先週、このコミュニティに参加したので、まだスタックオーバーフローで新しくなって申し訳ありません。 – anubismmt

関連する問題