让标签首先出现在 Kivy 中?

Getting a label to appear first in Kivy?

我在 Python 2.7 中使用 Kivy。我有一个发现蓝牙设备的简单程序。我想在实际扫描之前显示一个显示 "Scanning for Bluetooth devices" 的标签。然而,即使标签的代码放在扫描过程的上方,屏幕仍然是空白的,直到 运行 时设备被扫描。

class Boxes(FloatLayout, AnchorLayout):
    def __init__(self, **kwargs):
        global name 
        global devList 

        super(Boxes, self).__init__(**kwargs) 

        layout = AnchorLayout(anchor_x='right', anchor_y='top') 
        layout.add_widget(Label(text='[color=1f358e][font=tahoma]Scanningfor Bluetooth devices...[/color][/font]', markup = True, font_size='20sp', pos=(0,250)))
        self.add_widget(layout)

        devList = discover_devices() 

        box = BoxLayout(orientation='vertical')


        for device in devList: 
            name = str(lookup_name(device))
            if str(lookup_name(device)) == "":  
                name = "Unknown device" 
            deviceinfo = "[color=1f358e][font=tahoma]Device name: [color=1f358e][font=tahoma]" + str(name) + "\n[color=1f358e][font=tahoma]MAC address: [color=1f358e][font=tahoma]" + str(device) 
            box.add_widget(Button(text=deviceinfo, markup = True, font_size='17sp'))

        self.boxes.add_widget(box) 

我无法自己尝试,因为我无法让蓝牙模块工作,但我相信这应该可以。

from threading import Thread

class Boxes(FloatLayout, AnchorLayout):
    def __init__(self, **kwargs):
        global name
        global devList

        super(Boxes, self).__init__(**kwargs)

        layout = AnchorLayout(anchor_x='right', anchor_y='top')
        layout.add_widget(Label(text='[color=1f358e][font=tahoma]Scanning for Bluetooth devices...[/color][/font]', markup = True, font_size='20sp', pos=(0,250)))
        self.add_widget(layout)

        # Add the self. in front so we can access it from inside other functions
        self.box = BoxLayout(orientation='vertical')

        discoverThread = Thread(target=self.discover)
        discoverThread.start()


    def discover(self, *args)
        devList = discover_devices() 
        for device in devList: 
            name = str(lookup_name(device))
            if str(lookup_name(device)) == "":  
                name = "Unknown device" 
            deviceinfo = "[color=1f358e][font=tahoma]Device name: [color=1f358e][font=tahoma]" + str(name) + "\n[color=1f358e][font=tahoma]MAC address: [color=1f358e][font=tahoma]" + str(device) 
            self.box.add_widget(Button(text=deviceinfo, markup = True, font_size='17sp'))

        # Not sure what the .boxes is, but I suppose you know?
        self.boxes.add_widget(box)