我有一个kivy的微调器,我似乎无法使“text_autoupdate”功能正常工作。可以在此处找到文档:https://kivy.org/docs/api-kivy.uix.spinner.html
我的.py代码:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.spinner import Spinner
from kivy.uix.button import Button
from kivy.properties import ListProperty, BooleanProperty
class Port_Selection(Widget): # list all serial ports
ports = ["[None]"]
selection = ListProperty(['hit refresh'])
def port_refresh(self):
port = ["1","2","3"]
if port == []: # if none found
message = {"None"} # return "none"
port = message
self.ports = port
print self.ports
class SensorTest(Widget):
pass
class Sensor(App):
def build(self):
return SensorTest()
if __name__ == '__main__':
Sensor().run()
我的.kv代码:
#:kivy 1.0.9
<Port_Selection>:
Spinner:
text: 'Select Port'
text_autoupdate: True
values: root.ports
pos: root.x,root.y
Button:
text: 'Refresh Ports'
pos: root.x+100, root.y
on_press: root.port_refresh();
<SensorTest>:
Label:
font_size: 45
center_x: root.width/2
center_y: root.top - 50
text: "Sensor Testing"
Port_Selection:
pos: self.pos
如何让“text_autoupdate”功能正常工作?
答案 0 :(得分:0)
您忘记将端口定义为ListProperty
变化:
ports = ["[None]"]
要:
ports = ListProperty(["[None]"])