Python tkinter button.invoke 方法麻烦 [英] Python tkinter button.invoke method trouble
问题描述
我正在玩一个运动控制器,因此要单击"一个按钮,我会找出在任何给定点最靠近中间的按钮,然后使用 button.invoke() 方法.
I'm playing about with a motion controller, therefore to "click" a button I am finding out which button is closest to the middle at any given point and then using the button.invoke() method.
我确信按钮和设置工作正常,因为每当我点击按钮时 - 它们工作正常.但是,当通过button.invoke"方法调用按钮时,整个事情就会冻结.
I am confident the buttons and setup is working, because whenever I click the buttons - they work fine. However, When the button is called via the "button.invoke" method the whole thing just freezes up.
其他可能有用的信息:- gui 正在通过 .mainloop 函数在它自己的线程中更新.- 用鼠标点击时一切正常- button.invoke() 方法工作正常 - 在进行简单的打印操作时.仅在切换帧时冻结.
Other information which may be useful: - The gui is being updated in it's own thread through the .mainloop function. - Everything works fine when being clicked by a mouse - The button.invoke() method works fine - when doing a simple print operation. It only freezes when switching frame.
任何帮助都会很棒,谢谢.
Any help would be great, thanks.
推荐答案
您是说 mainloop 在与您创建小部件的地方不同的线程中运行?如果是这样,那是你的问题.您只能从一个线程调用 tkinter 函数.
Are you saying that mainloop runs in a separate thread from where you create the widgets? If so, that's your problem. You can only ever call tkinter functions from one thread.
这篇关于Python tkinter button.invoke 方法麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!