你开的多线程,将窗口的对象作为参数传进去,然后修改对象的控件就行了
import threading
import wx
import datetime
class MainForm(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent,
id,
title="test",
pos=(200, 150),
size=(900, 600))
self.id = id
self.MainForm_Panel = wx.Panel(self)
MainForm_Font = wx.Font(11, wx.DEFAULT, wx.DEFAULT, wx.NORMAL)
self.MainForm_SystemTime_Label = wx.StaticText(self.MainForm_Panel,
self.id,
label=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
pos=(705, 540),
style=wx.TE_RIGHT)
def task(frame):
while 1:
frame.MainForm_SystemTime_Label.Label = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
if __name__ == '__main__':
app = wx.App()
frame = MainForm(parent=None, id=-1)
frame.Show()
t = threading.Thread(target=task, args=(frame,))
t.setDaemon(True)
t.start()
app.MainLoop()
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢