问题描述
我有一个程序,该程序接收串行数据,并使用matplotlib通过Tkinter对其进行图形处理.我目前正在使用此功能,但是必须使用.after()函数来轮询队列中的数据.在我过去使用过的其他UI框架(C中的不同项目)中,有一种方法可以要求UI框架从mainloop调用给它的函数(在一段时间之后,在空闲期间,等等). .如果我尝试在不是mainloop的线程上使用.after(),它将无法正常工作并向我抱怨.
I have a program that receives serial data and uses matplotlib to graph it using Tkinter. I have this working currently, but I've had to use the .after() function to poll a queue for data. In other UI frameworks I've used in the past (different projects in C) there has been a way to ask the UI framework to call a function given to it from the mainloop (either after some amount of time, during idle, etc). If I try to use .after() on a thread which isn't the mainloop, it doesn't work and complains at me.
是否可以从主循环调用不是主循环的线程上提供的用户提供的函数?或者,是否有一种方法可以指示mainloop唤醒并在Queue获得一些数据时执行一些工作?
Is there a way to call a user supplied function, provided on a thread which isn't the mainloop, from the mainloop? Or, is there a way to instruct the mainloop to wake up and do some work if a Queue gets some data?
谢谢.
推荐答案
我听说您可以从非GUI线程调用event_generate
.如果您确实调用了event_generate
,则我读到应该将tail
的值赋予when
参数.
I've heard that you can call event_generate
from the non-GUI thread. If you do call event_generate
, I've read that you should give the value of tail
to the when
parameter.
我个人仅在一个项目中完成了此操作,但它似乎运行良好.
I've personally only done this in one project, but it seemed to work fine.
这篇关于有没有一种方法可以从不是主循环的线程请求在Tkinter主循环上调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!