当进程在后台 运行 时弹出 Kivy 显示

Pop up Kivy displaying while a process is running in background

在我的 kivy 项目中,我有一个按钮可以让我生成 .png 格式的 matplotlib 图。生成此图像需要时间(大约 20 秒),我想显示一个弹出窗口 window 来警告用户。

我尝试了什么:

<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 window 永远不会出现?

你猜对了吗?

提前致谢!

您正在覆盖 on_release 方法。

ActionButton:
    text: 'generate graph'
    on_release: 
        Factory.MyPopup().open()
        root.generate_graph() 

要在方法为 运行 时显示弹出窗口,我使用线程。当弹出窗口弹出时,该方法在线程中运行。

代码:

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
""")