【发布时间】:2016-04-15 13:55:59
【问题描述】:
我在 Python 2.7 中使用 Kivy。我有一个发现蓝牙设备的简单程序。我想在实际扫描之前显示一个显示“正在扫描蓝牙设备”的标签。但是,即使标签的代码放在扫描程序上方,屏幕仍然是空白的,直到设备在运行时被扫描。
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)
【问题讨论】:
-
大概是
discover_devices正在阻塞。相反,在单独的线程或进程中运行发现,一旦结果可用,更新您的小部件