我对kivy是全新的,我正试着为我的覆盆子做一个小的OSD。在
我的.kv文件如下所示:
BoxLayout:
orientation: 'vertical'
Label:
text_size: self.size
text: 'OSD'
font_size: 50
bold: True
halign: 'center'
valign: 'top'
size_hint: 1, .3
GridLayout:
cols: 2
Label:
text_size: self.size
text: 'Total entries in DB: '
font_size: 30
bold: False
halign: 'left'
size_hint: 1, .1
Label:
id: total_db
text_size: self.size
text: '366 000 '
font_size: 30
bold: True
color: 0, 1, 0, 1
halign: 'center'
size_hint: 1, .1
Label:
text_size: self.size
text: 'Info 1: '
font_size: 30
bold: False
halign: 'left'
size_hint: 1, .1
Label:
id: marked_update
text_size: self.size
text: '1328 '
color: 1, 0, 0, 1
font_size: 30
bold: True
halign: 'center'
size_hint: 1, .1
Label:
text_size: self.size
text: 'Activity'
font_size: 50
bold: True
halign: 'center'
valign: 'top'
size_hint: 1, .3
Label:
text: ''
font_size: 10
halign: 'center'
valign: 'top'
size_hint: 1, .08
GridLayout:
cols: 4
Button:
text: 'DS 01'
font_size: 25
background_color: 1, 0, 0, 1
Button:
text: 'DS 02'
font_size: 25
background_color: 0, 1, 0, 1
Button:
text: 'DS 03'
font_size: 25
background_color: 0, 1, 0, 1
Button:
text: 'DS 04'
font_size: 25
background_color: 0, 1, 0, 1
这就是我想要的样子。我想定期更新的两个标签文本与ID的价值,我提取稍后。。。但我甚至不能从python更新它们,如下所示:
^{pr2}$我正在考虑启动时钟,它调用update_txt函数,并且可以更改值,但是我一直得到错误的消息:ids不存在。。。等等,我是面向对象编程的新手,我搞不懂这个简单的事情
一些观察结果:
作为注释@eyllanesc,您不应该将子类命名为它继承的类。
self.label.ids.marked_update.txt
不正确。它应该是self.ids.marked_update.text
。将根小部件声明为kv规则。
你的代码可以是:
主.py
osd.kv:
但是,我建议使用kivy属性而不是id:
主.py:
osd.kv:
相关问题 更多 >
编程相关推荐