我从奇维开始,有一些问题。我有两个屏幕和按钮的代码。我怎么能在我所有的屏幕上贴上一个时间标签或类似的东西呢?在下面的代码中,我创建了一个屏幕,但我不想在单个屏幕上放置3个单独的标签
你知道吗主.py你知道吗
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import StringProperty, ObjectProperty
from kivy.clock import Clock
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import ScreenManager, Screen
Builder.load_string("""
<StartScreen>:
BoxLayout:
orientation: 'vertical'
Button:
text: 'Start >'
size_hint_y: None
hight: '40dp'
on_press: root.manager.current = 'second'
<SecondScreen>:
BoxLayout:
orientation: 'vertical'
Button:
text: 'Test2'
size_hint_y: None
hight: '40dp'
on_press: root.manager.current = 'end'
<EndScreen>:
BoxLayout:
Button:
text: 'Test3'
size_hint_y: None
hight: '40dp'
on_press: root.manager.current = 'start'
""")
#declarate both screens
class StartScreen(Screen):
pass
class SecondScreen(Screen):
pass
class EndScreen(Screen):
pass
#create the screen manager
sm = ScreenManager()
sm.add_widget(StartScreen(name='start'))
sm.add_widget(SecondScreen(name='second'))
sm.add_widget(EndScreen(name='end'))
class TutorialApp(App):
def build(self):
return sm
if __name__ == '__main__':
TutorialApp().run()
这是一个基于https://stackoverflow.com/a/18926863/6646710的可能解决方案
下面的代码定义了一个显示时间的标签。你知道吗
update函数从python
time
模块获取当前时间。时间用于更新标签的text
属性。在init
方法中,clock
模块用于每秒调度对此更新函数的调用。你知道吗下一步,我把这个标签添加到你所有的克维屏幕内的千伏字符串。你知道吗
最后的结果是
相关问题 更多 >
编程相关推荐