Kivy:如何在等待另一个小部件显示的同时显示小部件(均由同一事件调用) [英] Kivy: how to display a widget while waiting for another one to be displayed (both called from a same event)

查看:102
本文介绍了Kivy:如何在等待另一个小部件显示的同时显示小部件(均由同一事件调用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击确定"按钮时,我的kivy应用程序检索有时包含100多个文件夹的列表,并显示一个GridLayout,每个文件夹包含4列和1行.每行有3个可滚动标签和1个复选框.这个GridLayout有时需要接近12秒的时间才能生成,因此我想同时显示一些内容(标签,图像...).

When an "OK button" is clicking, my kivy app retrieves a list of sometimes 100+ folders and displays a GridLayout with 4 columns and 1 row per folder. Each row has 3 scrollable labels and 1 checkbox. This GridLayout sometimes takes close to 12 sec to be generated so I would like to display something (a label, an image...) in the meantime.

尝试1:我的确定按钮"调用一个def DisplayTable.我试图直接在DisplayTable的开头添加self.add_widget(Label_when_waiting)(因此在进行任何处理或生成GridLayout之前),但是Label_when_waiting仅在显示GridLayout时显示.

Attempt 1: My "Ok button" calls a def DisplayTable. I tried to simply add self.add_widget(Label_when_waiting) right at the beginning of DisplayTable (so before any processing or generating the GridLayout) but the Label_when_waiting is displayed only when GridLayout is displayed.

尝试2:我试图将def DisplayTable分为两个def,分别为Diplay_Label_when_waiting(由确定按钮"调用的一个)和DisplayTable:

Attempt 2: I tried to separate def DisplayTable into two def, Diplay_Label_when_waiting(the one called by the "OK button") and DisplayTable:

def Diplay_Label_when_waiting(self, *args):
    self.add_widget(Label_when_waiting)
    DisplayTable(self, *args)

但是,在这里再次显示Label_when_waiting仅在显示GridLayout时显示.

But here again, Label_when_waiting is displayed only when GridLayout is displayed.

那么我如何在GridLayout之前显示Label_when_waiting,因为这两个显示都必须由确定按钮"触发

So how can I display Label_when_waiting before GridLayout knowing that both displays have to be triggered by the "Ok button"

推荐答案

在显示标签后,使用 Clock.schedule_once 显示网格:

Use Clock.schedule_once to display the Grid after the label is shown:

def Diplay_Label_when_waiting(self, *args):
    self.add_widget(Label_when_waiting)
    Clock.schedule_once(lambda dt: DisplayTable(self, *args), 0)

您还可以使用 kivyoav 中的 delayable (免责声明-我是作者...)

You can also use delayable from kivyoav (DISCLAIMER - I'm the author ...)

from kivyoav.delayed import delayable

@delayable
def Diplay_Label_when_waiting(self, *args):
    self.add_widget(Label_when_waiting)
    yield 0.0 # delay of 0ms , will cause the UI to update...
    DisplayTable(self, *args)

这篇关于Kivy:如何在等待另一个小部件显示的同时显示小部件(均由同一事件调用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆