0
kivy 및 OOP에 새로 도입되었습니다.Kivy - 센서 데이터로 라벨을 업데이트 하시겠습니까?
kivy의 라벨을 임시 센서에서 가져온 데이터로 업데이트하려고합니다. 센서 데이터를 가져 오는 코드는 labeltempmod에 있습니다. 매초마다 호출되는 getTheTemp() 함수를 만들었습니다. 함수에서 Label (텍스트 = (형식 (thetemp)), font_size = 80)을 통해 레이블의 텍스트를 할당하려고합니다. 프로그램에서이를 무시합니다. 여기서 내가 뭘 잘못하고 있니?
<LabelWidget>:
orientation: 'vertical'
TextInput:
id: my_textinput
font_size: 80
size_hint_y: None
height: 100
text: 'default'
FloatLayout:
Label:
id: TempLabel
font_size: 150
text: 'Temp Test'
감사 : 여기
#This is a test to see if I can write the temp to label
import labeltempmod
import kivy
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
def getTheTemp(dt):
thetemp = labeltempmod.readtemp()
Label(text=(format(thetemp)), font_size=80)
print thetemp
class LabelWidget(BoxLayout):
pass
class labeltestApp(App):
def build(self):
# call get_temp 0.5 seconds
Clock.schedule_interval(getTheTemp, 1)
return LabelWidget()
if __name__ == "__main__":
labeltestApp().run()
는 kivy 언어 파일입니다.
멋진 사람 감사합니다! 그거야. 관심있는 사람들에게 형식 (thetemp)을 추가해야했습니다. 레이블 텍스트는 문자열 만 허용합니다. OOP는이 멍청이에게 약간 혼란 스럽습니다. 그러나 나는 그것을 알아 내기 위해 계속 노력할 것이다. – Core2
아주 정밀하지 않은 온도 센서를 사용하고 있습니다. 나는 판독 값을 부드럽게하기 위해 일차 지연 필터를 소개하고자합니다. 이렇게하면 이전 temp를 labeltempmod.readtemp()에 다시 전달해야합니다. 그래서 getTheTemp (self, dt)는 임시 변수를 반환해야합니다. getTheTemp (self, dt)는 clock.schedule 행에 의해 호출됩니다. temp를 __init__ 함수로 반환하면 getTheTemp에 다시 전송되어 다음에 호출 될 때 labelTempmod.readtemp (thetemp)로 보낼 수 있습니다. – Core2
@ Core2 내 대답을 업데이트 할 것입니다 –