简体   繁体   English

appJar状态栏不会实时更新

[英]appJar status bar doesn't update in real time

I've set up a simple appJar UI, which has an "execute" button that calls a function containing code that takes a minute to run. 我已经建立了一个简单的appJar UI,其中包含一个“执行”按钮,该按钮调用包含代码的函数,该函数需要一分钟的时间才能运行。 I have injected my gui() variable, app , into this function. 我已经将gui()变量app注入到该函数中。

There are 4 major steps, after each of which I would like a Statusbar to update to reflect that a step has been completed. 有四个主要步骤,在每个主要步骤之后,我希望状态栏进行更新以反映一个步骤已完成。 However, what tends to happen is that as the function code runs, the GUI becomes unresponsive and it isn't until the code completes execution that ALL of the changes to the status bar are displayed at once. 但是,趋向于发生的是,随着功能代码的运行,GUI变得无响应,并且直到代码完成执行后,状态栏的所有更改才立即显示出来。

My question is how should I be handling the UI such that the Statusbar is updated in real time? 我的问题是我应该如何处理UI以使状态栏实时更新?

appJar is just a wrapper around python tkinter module from standard library. appJar只是标准库中python tkinter模块的包装器。

While your code is running, the ui is not running, thus it becomes unresponsive. 当您的代码正在运行时,ui并未运行,因此它没有响应。 If you want the ui to remain responsible, you have to return control from your code to the ui library from time to time. 如果您希望ui保持责任,则必须不时将控制权从代码返回给ui库。

That can be done by calling gui.topLevel.update() in your code, or by using asynchronous programming and having the main async loop call it, or by using threads. 这可以通过在代码中调用gui.topLevel.update()来完成,或者通过使用异步编程并让主异步循环调用它,或者通过使用线程来完成。

Which one of those is the best, depends on what your program is doing. 其中哪一个最好,取决于您的程序在做什么。

appJar also has built in support for threads: http://appjar.info/pythonThreads/ appJar还内置了对线程的支持: http ://appjar.info/pythonThreads/

You can call the function that takes a long time in a thread: app.thread(myFunction, param1, param2) 您可以在一个线程中调用需要很长时间的函数: app.thread(myFunction, param1, param2)

And, if you want to get the thread to update the GUI, you'll need to use the update queue : app.queueFunction(app.setMeter, "myMeter", 50) 而且,如果要获取线程来更新GUI,则需要使用更新队列app.queueFunction(app.setMeter, "myMeter", 50)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM