我在這裏使用OSC庫蟒蛇寫了一個服務是我的代碼:更改按鈕文本動態地kivy
def __init__(self, * * kwargs):
super(ElectronApp, self).__init__(* * kwargs)
self.electronController = ElectronController()
self.button = ElectronTHView()
def build(self):
return Builder.load_file('ElectronApp.kv')
def build(self):
self.button = ElectronTHView()
self.service = None
self.start_service()
osc.init()
oscid = osc.listen(port = 3002)
osc.bind(oscid, self.display_message, '/message')
osc.bind(oscid, self.date, '/date')
Clock.schedule_interval(lambda * x: osc.readQueue(oscid), 0)
self.root = Builder.load_file('ElectronApp.kv')
return self.root
....
def date(self, message, * args):
print(message[2])
# here i get message from my service and i want to update text on button
self.button.ids.tem.text = message[2]
class ElectronAppMain(BoxLayout):
pass
class ElectronAppMainView(TabbedPanel):
pass
class ElectronAppBottomBar(BoxLayout):
pass
class ElectronButton(Button):
pass
class ElectronTHView(BoxLayout):
pass
* .KV文件代碼:
ElectronAppMain:
<ElectronAppMain>:
padding: "-2dp"
orientation: "vertical"
canvas.before:
Rectangle:
size: self.size
pos: self.pos
source: "background.png"
ElectronAppMainView:
ElectronAppBottomBar:
<ElectronAppBottomBar>:
size_hint: 1, None
height: "50dp"
padding: "0dp"
orientation: "horizontal"
spacing: "0dp"
ElectronButton:
text: "STOP"
size_hint: 1, None
height: "50dp"
on_release:
ElectronButton:
text: "EXIT"
size_hint: 1, None
height: "50dp"
on_release:
<ElectronAppMainView>:
tab_pos: "top_left"
do_default_tab: False
tab_height: "50dp"
tab_width: root.width/3
background_image:
font_size: "12dp"
background_normal:
background_down:
text: "T/H"
font_name: "fonts/Roboto-Medium.ttf"
ElectronTHView:
TabbedPanelItem:
font_size: "12dp"
background_normal:
background_down:
text: "CUSTOM"
font_name: "fonts/Roboto-Medium.ttf"
TabbedPanelItem:
font_size: "12dp"
background_normal:
background_down:
text: "PATTERN"
font_name: "fonts/Roboto-Medium.ttf"
<ElectronTHView>:
orientation: "vertical"
spacing: "5dp"
padding: "10dp"
ElectronButton:
id: temp
background_normal: ....
background_down:
size_hint: 1, .5
height: self.height
text: "Temperature"
on_release:
ElectronButton:
background_normal:
background_down:
size_hint: 1, .5
height: self.height
text: "Humidity"
on_release:
我想更多的選擇,但一無所獲。 ..當我嘗試
def date(self, message, *args):
print(message[2])
#here i get message from my service and i want to update text on button
self.button.ids.tem.text = message[2]
更新文本我收到這樣的錯誤:
Sat Oct 22 16:35:27 2016
OSC callback /date caused an error: 'super' object has no attribute '__getattr__'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/kivy/lib/osc/OSC.py", line 288, in dispatch
callbackfunction(message, source)
File "main.py", line 128, in date
self.button.ids.temp.text = '1'
File "kivy/properties.pyx", line 757, in kivy.properties.ObservableDict.__getattr__ (kivy/properties.c:11882)
AttributeError: 'super' object has no attribute '__getattr__'
---------------------
[INFO ] [Base ] Leaving application in progress...
[ERROR ] [OSC ] Error in Tuio recv()
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/kivy/lib/osc/oscAPI.py", line 229, in run
message = self.socket.recv(65535)
error: [Errno 4] Interrupted system call
我是新的基維...在此先感謝您的幫助!
請仔細格式化您的問題。現在無法讀取它 – agg3l
嗨!我做到了! – Clark
這種方式更好。如果你可以引用來自python的堆棧跟蹤(完整的錯誤文本),如果可用的話,對於有人來協助你來說,它會簡單得多。 – agg3l