在后台运行进程时弹出Kivy显示 [英] Pop up Kivy displaying while a process is running in background
本文介绍了在后台运行进程时弹出Kivy显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的kivy项目中,我有一个按钮可以让我生成.png格式的matplotlib图.生成此图像需要花费时间(大约20秒),我想显示一个弹出窗口来警告用户.
In my kivy project, I have a button allowing me to generate a matplotlib graph in .png format. Generating this image takes time (around 20 seconds), and I would like to display a pop-up window to warn the user.
我尝试了什么:
<MyPopup@Popup>:
auto_dismiss: False
Button:
text: 'This could take time, please wait :) '
on_release: root.dismiss()
和:
ActionButton:
text: 'generate graph'
on_release: Factory.MyPopup().open()
#on_release: root.generate_graph()
不幸的是,如果我取消注释第二个"on_release",则pop_up窗口将永远不会出现?
Unfortunately, if I uncomment the second "on_release", the pop_up window never appears?
您有任何猜想吗?
先谢谢您!
推荐答案
要在方法运行时显示弹出窗口,请使用线程.当弹出窗口启动时,该方法在线程中运行.
To display a popup while a method is running I use threads. When the popup fires up, the method runs in a thread.
代码:
def popupThread(self):
#set the popup structure
self.popup = ActivityBox(self)
self.popup.open()
# run the method in threads
t1 = threading.Thread(target = self.someMethod)
t1.start()
弹出窗口在Builder.load_string()
中定义:
def build(self):
sm = Builder.load_string("""
<ActivityBox>:
size_hint: 1, .7
auto_dismiss: False
title: 'some activity'
title_align: "center"
title_size: 30
BoxLayout:
orientation: "vertical"
Label:
font_size: '30sp'
text: 'work in progress'
BoxLayout:
orientation: "horizontal"
spacing: 10
size_hint: 1, .5
""")
这篇关于在后台运行进程时弹出Kivy显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文