i kind of new kivy , trying display time in it
here python code snippet(removed unnecessary screens/parts arbitrary reasons):
from kivy.app import app kivy.uix.screenmanager import screenmanager, screen import time kivy.uix.label import label class myscreen(screen): def update(self, *args): self.timeb.text = time.asctime() return time.asctime() class myapp(app): def build(self): x=myscreen() root = screenmanager() clock.schedule_interval(x.update, 1) root.add_widget(password(name='screen0')) root.add_widget(correct(name='screena')) root.add_widget(myscreen(name='screen1')) s=[x,root] in s: return if __name__ == '__main__': myapp().run()
.kv file(removed unnecessary screens/parts arbitrary reasons):
myscreen: <myscreen>: # timeb:time_box boxlayout: orientation: "horizontal" pos_hint: {'top':1} height: "40dp" size_hint_y: none label: id:time_box text:root.update() size_hint_x: 6 font_size:30 font_name:"roboto-light.ttf"
as can see in code have added few screens screen first come if change the
s=[x,root] in s: return
to just
return root
then time doesn't update itself.
could help?
thanks!
maybe forgot type something, kv coded wrong. why there hanging myscreen:
, assigned to? need main rule somewhere, see none. assigned myscreen:
<myapp>:
normal return myscreen()
or return some_scrmanager
, works.
from kivy.app import app kivy.uix.screenmanager import screenmanager, screen kivy.clock import clock import time kivy.uix.label import label kivy.lang import builder builder.load_string(''' <myapp>: myscreen: <myscreen>: # timeb:time_box boxlayout: orientation: "horizontal" pos_hint: {'top':1} height: "40dp" size_hint_y: none label: id:time_box text:root.update() size_hint_x: 6 font_size:30 ''') class myscreen(screen): def update(self, *args): self.timeb.text = time.asctime() return time.asctime() class myapp(app): def build(self): x=myscreen() root = screenmanager() clock.schedule_interval(x.update, 1) root.add_widget(myscreen(name='screen1')) s=[x,root] in s: return if __name__ == '__main__': myapp().run()
and same kv, more reasonable python code looke this:
<screenmgr>: myscreen: <myscreen>: ... class myscreen(screen): def __init__(self, **kw): super(myscreen, self).__init__(**kw) clock.schedule_interval(self.update, 1) def update(self, *args): self.timeb.text = time.asctime() return time.asctime() class screenmgr(screenmanager): pass class myapp(app): def build(self): x=myscreen() root = screenmgr() root.add_widget(myscreen(name='screen1')) return root if __name__ == '__main__': myapp().run()
because there's no need call update()
screen class in building function , outside class want use presuming it'll run forever(do plan stop time?).
Comments
Post a Comment