wxPython持续更新pan

2024-10-02 20:30:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我是wxPython的新人,一个问题都解决不了。我需要不断更新面板与时钟值。我有一个解决方案,但在这种情况下,我不能正常关闭窗口(alt+f4不起作用)。 我也不明白.Update.Refresh和when.Destroy之间的区别是什么?在

有人能再读一本好书吗?如何用wxPython编程? 谢谢你的帮助。在

class TimeDatePanel(wx.Panel):
def __init__(self, parent, ID=ID_TIMEDATE, pos=wx.DefaultPosition, size=(50, 50), controller=None):
    wx.Panel.__init__(self, parent, ID, pos, size, wx.RAISED_BORDER)
    self.controller = controller
    transCoded = controller.transCodes
    layout = wx.GridSizer(5,2,0,10)
    layout.Add(wx.StaticText(self, wx.ID_ANY, transCoded.get("Time & Date")))
    layout.Add(wx.StaticText(self, wx.ID_ANY, ""), 0,flag=wx.ALL)
    layout.Add(wx.StaticText(self, wx.ID_ANY, transCoded.get("Local time")), 0,flag=wx.ALL|wx.ALIGN_RIGHT)
    self.LT = wx.StaticText(self, wx.ID_ANY, "")
    layout.Add(self.LT)
    layout.Add(wx.StaticText(self, wx.ID_ANY, transCoded.get("UTC")), 0,flag=wx.ALL|wx.ALIGN_RIGHT)
    self.UTC = wx.StaticText(self, wx.ID_ANY, "")
    layout.Add(self.UTC)
    layout.Add(wx.StaticText(self, wx.ID_ANY, transCoded.get("Julian day")), 0,flag=wx.ALL|wx.ALIGN_RIGHT)
    self.JD = wx.StaticText(self, wx.ID_ANY, "")
    layout.Add(self.JD)
    layout.Add(wx.StaticText(self, wx.ID_ANY, transCoded.get("Local sidereal time")), 0,flag=wx.ALL|wx.ALIGN_RIGHT)
    self.LST = wx.StaticText(self, wx.ID_ANY, "")
    layout.Add(self.LST)
    self.SetSizer(layout)
    self.updateTimeDate()
    self.Fit()

    wx.EVT_PAINT(self, self.onPaint)

def onPaint(self, event=None):
    self.updateTimeDate()

def updateTimeDate(self):
    mechanics = self.controller.mechanics
    self.LT.SetLabel(str(mechanics.getLT()))
    self.UTC.SetLabel(str(mechanics.getUTC()))
    self.JD.SetLabel(str(mechanics.getYD()))
    self.LST.SetLabel(str(mechanics.getLST()))

Tags: selfrightaddidgetanyallflag
1条回答
网友
1楼 · 发布于 2024-10-02 20:30:12

如果您需要每隔一段时间更新一次时钟,为什么不使用AnalogClock、LEDNumberCtrl或TimeCtrl来更新它定时器?以下教程将帮助您处理计时器部分:http://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/

前两个小部件会自行更新。当您休息StaticText控件或其他普通小部件的值时,应该必须调用Update、Refresh或Layout。只需使用SetValue或SetLabel即可。在

罗宾·邓恩有一本老书叫做“wxPython-in-Action”,这本书在很大程度上仍然很棒。今年还出版了一本由科迪·普雷科德撰写的wxPython食谱。在

相关问题 更多 >