Tkinter window says (not responding) but code is running

前端 未结 1 1318
星月不相逢
星月不相逢 2020-12-16 16:13

I have a program that runs a long process after you click an action button. As the process is running the root window will say that it is not responding even though I know

相关标签:
1条回答
  • 2020-12-16 16:49

    While you can call root.update() in your loop, this will still produce some (potentially) undesirable side-effects.

    1. The program may act laggy, meaning it takes a long time to respond to user input.
    2. You will only be able to run this one action. Any other action has to wait for this to finish.

    As an alternative I would suggest that you implement simple multi-threading. Python multithreading is pretty simple, and will prevent both of these drawbacks. You will be able to execute your long running code, while still providing a clean and responsive UI.

    If your application is trivially parallelizable, you could use multiple threads to decrease running time. Ex. Thread 1 handles entries 1-100, while thread 2 handles entries 101-200.

    0 讨论(0)
提交回复
热议问题