问题描述
我正在为我开发的命令行实用程序编写 Kivy UI.一切正常,但有些进程可能需要几秒钟到几分钟的时间来处理,我想向用户提供一些指示,表明该进程正在运行.理想情况下,这将是一个旋转轮或加载栏或其他东西的形式,但即使我可以更新我的显示以向用户显示一个进程正在运行,它也会比我现在拥有的更好.
I am writing a Kivy UI for cmd line utility I have developed. Everything works fine, but some of the processes can take from a few seconds to a few minutes to process and I would like to provide some indication to the user that the process is running. Ideally, this would be in the form of a spinning wheel or loading bar or something, but even if I could update my display to show the user that a process is running, it would be better than what I have now.
目前,用户在主 UI 中按下按钮.这会弹出一个弹出窗口,向用户验证一些关键信息,如果他们对这些选项感到满意,他们会按下运行"按钮.我已经尝试打开一个新的弹出窗口来告诉他们进程正在运行,但是因为在进程完成之前显示不会更新,所以这不起作用.
Currently, the user presses a button in the main UI. This brings up a popup that verifies some key information with the user, and if they are happy with those options, they press a 'run' button. I have tried opening a new popup to tell them that the process is running, but because the display doesn't update until the process finishes, this doesn't work.
我有很多编码经验,但主要是在数学和工程方面,所以我对 UI 设计和处理事件和线程非常陌生.一个简单的独立示例将不胜感激.
I have a lot of coding experience, but mostly in the context of math and engineering, so I am very new to the designing of UIs and having to handle events and threads. A simple self-contained example would be greatly appreciated.
推荐答案
我最近正在解决你描述的问题:显示在进程完成之前不会更新
I was recently tackling the problem you described: display doesn't update until the process finishes
这是我在#Kivy IRC 频道中@andy_s 的帮助下完成的一个完整示例:
Here is a complete example that I got working with the help of @andy_s in the #Kivy IRC channel:
我的 main.py:
My main.py:
我的例子.kv:
如果你运行这个例子,你可以点击Click Me
按钮,它应该会打开一个模态/弹窗形式的进度条".此弹出窗口将保持打开 5 秒钟而不会阻塞主窗口.5秒后,弹窗会自动消失.
If you run this example, you can click the Click Me
button, which should open up a "progress bar" in the form of a modal/pop-up. This pop up will remain open for 5 seconds without blocking the main window. After 5 seconds, the pop up will automatically be dismissed.
这篇关于在 Kivy 中构建简单的进度条或加载动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!