Python Tkinter多线程冻结GUI

时间:2019-06-13 19:49:00

标签: python multithreading tkinter

我在Tkinter的AI游戏中需要4个独立的线程,每个线程都有“响应时间”,例如:time.sleep(0.15)。问题是每个线程都在等待一段时间,总之,tkinter gui被永久冻结。

我尝试为AI创建线程,但是当我启动其中一些线程时,tkinter会冻结

我在其中创建线程(并且可能冻结的代码)的一部分

...
def start():
    #create some local variables
    ...
    #create threads
    ai_process = Thread(target=ai)
    hu_bullet_process = Thread(target=fire)
    co_bullet_process_vert = Thread(target=firecovert)
    co_bullet_process_horz = Thread(target=firecohorz)
    ai_process.start()
def ai():
    #some conditions, which can start other threads
    time.sleep(difficulty)
    ai()
...

期望:4个线程有延迟但不影响tkinter主线程 现实:即使1个线程冻结了tkinter gui

0 个答案:

没有答案