TextCtrl 由于某种原因在无限循环中时无法工作,这是我的代码:
while 1:
localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
i = i + 1
#print str(i)
serRead = ser.readline()
serSplit = serRead.split(",")
#this works
print str(i)+', '+tempOrShock+', '+localtime+', '+serSplit[1]
#this doesn't
self.displayTextCtrl.WriteText(str(i)+', '+tempOrShock+', '+
localtime+', '+serSplit[1])
这个无限 while 循环在按钮单击事件中,我基本上是在单击按钮后运行无限循环并告诉我的 TextCtrl 不断写出内容,但它不起作用。但是,打印语句工作正常。知道为什么会这样吗?
请您参考如下方法:
我怀疑 wxpython 在它的主循环中有一些它需要做的处理(调度事件等等)。但是在您从事件处理程序返回之前,该循环无法运行。您最好设置一个计时器来定期更新您的文本控件。
