Python/Tkinter:Tkinter StringVar(IntVar等)线程安全吗? [英] Python/Tkinter: Are Tkinter StringVar (IntVar, etc) thread safe?

查看:232
本文介绍了Python/Tkinter:Tkinter StringVar(IntVar等)线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tkinter StringVar(IntVar,FloatVar等)是否是线程安全的,例如.后台线程可以读取或写入这些对象吗?还是我必须使用队列在后台线程和主Tkinter GUI线程之间传递信息,并让主Tkinter线程弹出队列并相应地更新应用程序的StringVar?

Are Tkinter StringVar (IntVar, FloatVar, etc) thread safe, eg. can a background thread read or write to these objects? Or must I use a Queue to pass information between my background thread and my main Tkinter GUI thread and have my main Tkinter thread pop the Queue and update the application's StringVar's accordingly?

我知道我的应用程序的后台线程一定不能直接读取或编写Tkinter窗口小部件,但是我不清楚StringVar(或它们的同类)是否被认为是窗口小部件,或者它们是否是从窗口小部件中移走的,足以保证线程安全的对象读取和/或写入的后台线程.

I know my application's background threads must not read or write a Tkinter widget directly but I'm unclear on whether StringVar's (or their ilk) are considered widgets or if they are objects far enough removed from widgets that they are thread safe for background threads to read and/or write.

推荐答案

绝对走队列路线. Tkinter中没有任何东西可以确保线程安全:(

Definitely go the Queue route. Nothing in Tkinter is setup for being threadsafe :(

这篇关于Python/Tkinter:Tkinter StringVar(IntVar等)线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆