我正在尝试在Raspberry Pi上创建一个两屏Kivy触摸屏界面,该界面的作用类似于可选的菜单界面,以根据选择进行功能。
屏幕1: 显示八个块-每个块由一个由Label,Image,Timer,Button组成的BoxLayout组成。
屏幕2: 带有名称和图片以及计时器值的预定义块列表。
现在让我们说我想将屏幕1上的块2的值设置为我在屏幕2上选择的值,我想按屏幕1上的块2的按钮,它会打开屏幕2,然后选择其中一项。现在,根据我在screen2上选择的内容,它现在应该加载该项目的值,并使用Label,Image,Timer更新screen1上的块2。计时器应该是倒数计时器。
我有可以显示screen1和screen2的基本布局,但是正在与值更新概念和多个块打交道。该规范仍然有些混乱,但是希望它能给出我要做什么的想法-在发布问题后将其粘贴。屏幕2仍然没有值。
# class for aqua.kv file
class MainScreen(Screen):
pass
# class for screen.kv file
class SelectScreen(Screen):
pass
class Tray1(Screen):
pass
# class for date.kv file
class Date(BoxLayout,EventDispatcher):
def __init__(self,**kwargs):
super(Date,self).__init__(**kwargs)
Builder.load_file('date.kv')
Builder.load_file('tray1.kv')
class MyApp(App):
time = StringProperty()
def update(self,*args):
self.time = str(time.asctime())
def build(self):
Clock.schedule_interval(self.update,1)
# Set up the layout:
return Builder.load_file('screen.kv')
if __name__ == '__main__':
MyApp().run()
ScreenManager:
id: screen_manager
MainScreen:
id: main_screen
name: 'MainScreen'
manager: 'screen_manager'
SelectScreen:
id: select_screen
name: 'SelectScreen'
manager: 'screen_manager'
# on_release: background_color = 1,0,0,1
<MainScreen>:
BoxLayout:
canvas.before:
Color:
rgba: .5,.6,.7,1
Rectangle:
pos: self.pos
size: self.size
orientation:'vertical'
BoxLayout:
size_hint:1,.2
Date:
BoxLayout:
orientation: 'horizontal'
# size_hint: .2,1
BoxLayout:
orientation: 'vertical'
Label:
id:btn_tray1
font_size: 30
Image:
source:"logo.png"
Tray1:
Button:
id:btn_tray1_1
font_size: 30
text:"Tray1"
on_release: app.root.current = "SelectScreen"
#on_release: app.root.current = "SelectScreen"
# on_release: btn_tray1.background_color = 1,0,0,1
Button:
id:btn_tray2
font_size: 30
text:"Tray2"
on_release: app.root.current = "SelectScreen"
Button:
id: btn_tray3
font_size: 30
text:"Tray3"
on_release: app.root.current = "SelectScreen"
<SelectScreen>:
BoxLayout:
canvas.before:
Color:
rgba: .5,.6,.7,1
Rectangle:
pos: self.pos
size: self.size
orientation:'vertical'
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'horizontal'
# size_hint: .2,1
Button:
size_hint:1,.2
id:btn_tray5
font_size: 30
text:"Tray5"
on_release: app.root.current = "MainScreen"
# on_release: btn_tray1.background_color = 1,0,0,1
Button:
size_hint:1,.2
id:btn_tray6
font_size: 30
text:"Tray6"
on_release: app.root.current = "MainScreen"
Button:
size_hint:1,.2
id: btn_tray7
font_size: 30
text:"Tray7"
on_release: app.root.current = "MainScreen"
# on_release: btn_tray3.background_color = 1,0,0,1
Button:
size_hint:1,.2
id: btn_tray8
font_size: 30
text:"Tray8"
on_release: app.root.current = "MainScreen"
# on_release: btn_tray4.background_color = 1,0,0,1