在Kivy中为方框布局中的所有子项设置全局字体大小



我在Kivy中的框布局中有三个按钮。我希望他们每个都有相同的字体大小。有没有一种方法可以指定框布局中所有小部件的字体大小,而不必在子小部件中定义字体大小?

这个盒子布局的.kv文件的一部分看起来像这个

BoxLayout:
id: action_buttons
orientation: "horizontal"
size_hint: 1, None
height: "100dp" 

Button:
id: cust_query
text: "Send Custom Query"
font_size: 24
Button:
id: man_query
text: "Manually Check Tables"
font_size: 24
ToggleButton:
id: sched_query
text: "Start Query Schedule"
on_state: root.schedule_switch_state(self)
font_size: 24

有没有一种更像这样的方法:

BoxLayout:
id: action_buttons
orientation: "horizontal"
size_hint: 1, None
height: "100dp"
font_size: 24    

Button:
id: cust_query
text: "Send Custom Query"
Button:
id: man_query
text: "Manually Check Tables"
ToggleButton:
id: sched_query
text: "Start Query Schedule"
on_state: root.schedule_switch_state(self)

我想我找到了一个解决方案:font_size: self.parent.font_size

*.kv

#:kivy 2.0.0
<Main>:

BoxLayout:
id: myboxlayout
orientation: "horizontal"
size: root.size
font_size: 24

Button:
text: "Button 1"
font_size: self.parent.font_size

Button:
text: "Button 2"
font_size: self.parent.font_size

首先为方框布局设置字体大小

然后将按钮的字体大小指向其父的字体大小

//希望这有帮助:(

最新更新