Kivy GUI冻结

问题描述 投票:0回答:1

我的KIVY-GUI随机冻结,我不太清楚为什么。我从python端更改了两个小部件(即启用复选框,更改textinput文本等),有时从循环中更改了(即一个接一个地启用6个复选框)。我认为冻结主要是在我一次禁用许多小部件时发生的,但是当只更改一个小部件时也会发生冻结。通过转到外壳程序窗口并按CTRL + C,我可以再次冻结GUI。有时,GUI随后会崩溃,并显示以下错误:

[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "GUI_MELC.py", line 637, in <module>
     GUI_MELC().run()
   File "C:\Python37\lib\site-packages\kivy\app.py", line 855, in run
     runTouchApp()
   File "C:\Python37\lib\site-packages\kivy\base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Python37\lib\site-packages\kivy\core\window\window_sdl2.py", line 747, in mainloop
     self._mainloop()
   File "C:\Python37\lib\site-packages\kivy\core\window\window_sdl2.py", line 479, in _mainloop
     EventLoop.idle()
   File "C:\Python37\lib\site-packages\kivy\base.py", line 339, in idle
     Clock.tick()
   File "C:\Python37\lib\site-packages\kivy\clock.py", line 563, in tick
     current = self.idle()
   File "C:\Python37\lib\site-packages\kivy\clock.py", line 543, in idle
     usleep(1000000 * sleeptime)
   File "C:\Python37\lib\site-packages\kivy\clock.py", line 727, in usleep
     _usleep(microseconds, self._sleep_obj)
   File "C:\Python37\lib\site-packages\kivy\clock.py", line 405, in _usleep
     _kernel32.WaitForSingleObject(obj, 0xffffffff)
 KeyboardInterrupt

一些我如何禁用小部件的示例代码(如果您可以这样调用,可能是最耗时的):

    guiElements = []
    temp=['redAll', 'greenAll', 'blueAll']
    guiElements.extend(temp)

    for i in range(6):
        temp1='red'+str(i)
        temp2='gre'+str(i)
        temp3='blu'+str(i)
        temp4='red'+str(i)+'Val'
        temp5='gre'+str(i)+'Val'
        temp6='blu'+str(i)+'Val'
        tempList=[temp1, temp2, temp3, temp4, temp5, temp6]
        guiElements.extend(tempList)

    def disableMainBoxGUI(self, status):
        #self.getGUIElements()
        for i in self.guiElements:
            self.ids[i].disabled = status

是否有避免GUI冻结的方法?我是否需要添加time.sleep(XX)或其他内容?

python widget kivy freeze disable
1个回答
0
投票

只是一些简单的建议-学习使用线程。它并没有那么复杂,它对于长循环运行很有帮助。我建议您阅读this以使自己熟悉。线程化将加速您的应用程序并消除GUI冻结。我几乎在每个项目中都使用ThreadPoolExececutor,但是您需要的只是一个简单的守护线程。希望对您有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.