本文介绍了在进程运行背景时以奇异的方式显示某些内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用matplotlib离开我的kivy应用程序时,我正在尝试生成图形.生成这些图的过程时间约为20秒,我想在这段时间内警告用户.我尝试使用Kivy弹出式窗口,但没有用.我试图添加标签,但它似乎也不起作用.这就是为什么我真的需要帮助!

I'm trying to generate a graph when i'm leaving my kivy app using matplotlib.The process time to generate these graphs is about 20 seconds and i would like to warn the user during this time. I tried to use a Kivy pop up, and it didn't work. I tried to add a label, but it doesn't seems to work either. That's why I really need help !

我的代码:

    def fermerBanc(self):  

        list_argument_graph=[]
        list_argument_graph.append(passerelle.graph1.y_low_min)
        list_argument_graph.append(passerelle.graph1.y_low_max)
        list_argument_graph.append(passerelle.graph1.y_high_min)
        list_argument_graph.append(passerelle.graph1.y_high_max)
        list_argument_graph.append(passerelle.graph1.setTaille)

        list_argument_graph_1=list(list_argument_graph)
        list_argument_graph_1.insert(0, chemin1)

        list_argument_graph_2=list(list_argument_graph)
        list_argument_graph_2.insert(0, chemin2)

        list_argument_graph_3=list(list_argument_graph)
        list_argument_graph_3.insert(0, chemin3)

        list_argument_graph_4=list(list_argument_graph)
        list_argument_graph_4.insert(0, chemin4)

        if(passerelle.graph1.flagGraph):

            p1 = Process(target=process_graph, args=(list_argument_graph_1,))
            p2 = Process(target=process_graph, args=(list_argument_graph_2,))
            p3 = Process(target=process_graph, args=(list_argument_graph_3,))
            p4 = Process(target=process_graph, args=(list_argument_graph_4,))

            try:
                p1.start()
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 1, fichier vide')

            try:
                p2.start()  
                pass
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 2, fichier vide')

            try:
                p3.start()
                pass
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 3, fichier vide')

            try:
                p4.start()
                pass              
            except AttributeError:
                Logger.warning('fermerBanc: impossible de generer un graph 4, fichier vide')

            self.msgWarning = Label(text="Merci de patienter...", font_size='55sp', size=(100, 50), pos_hint={'center_x': .5, 'center_y':.5})
            self.add_widget(self.msgWarning)

            p1.join()
            p2.join()
            p3.join()
            p4.join()

        exit()

如果我注释了几个processexit()命令,则我的标签正常显示

Edit : If I comment the several processand the exit() command my Label is displaying normally

推荐答案

由于

您必须使用kivy Clock.schedule_once()方法: kivy时钟doc

you have to use the kivy Clock.schedule_once() method : kivy clock doc

我的情况是,我只是创建了一个负责以下内容的函数fermerbanc_schedule:

I my case, I just create a function fermerbanc_schedule in charge of :

  • 在屏幕上显示等待消息
  • 通过schedule_once

def fermerBanc_schedule(self,* args): self.msgWarning = Label(text ="Merci de Patienter ...",font_size ='55sp',size =(100,50),pos_hint = {'center_x':.5,'center_y':.5}) self.add_widget(self.msgWarning) Clock.schedule_once(lambda dt:self.fermerBanc(self,* args),0)

def fermerBanc_schedule(self, *args): self.msgWarning = Label(text="Merci de patienter...", font_size='55sp', size=(100, 50), pos_hint={'center_x': .5, 'center_y':.5}) self.add_widget(self.msgWarning) Clock.schedule_once(lambda dt: self.fermerBanc(self, *args), 0)

这篇关于在进程运行背景时以奇异的方式显示某些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:58