这是我mykv.kv
文件的相关代码段:
<RemoveScreen>:
MyLayout:
MyLogo:
GridLayout:
rows: 6
cols: 2
padding: 100,80,100,80
Label:
font_size: "20sp"
bold: True
color: [1,1,0,1]
text: "Part number:"
Label:
text: "Box 02"
Label:
font_size: "20sp"
bold: True
color: [1,1,0,1]
text: "Part description:"
Label:
text: "Box 04"
Label:
font_size: "20sp"
bold: True
color: [1,1,0,1]
text: "Quatity on hand:"
Label:
#font_size: "20sp"
text: "Box 06"
Label:
font_size: "20sp"
bold: True
color: [1,1,0,1]
text: "Bin location:"
Label:
text: "Box 08"
Label:
font_size: "20sp"
bold: True
color: [1,1,0,1]
text: "Direction:"
Label:
text: "Box 10"
Label:
font_size: "20sp"
bold: True
color: [1,1,0,1]
text: "Scan time:"
Label:
text: "Box 12"
MyButtons:
#buttons
上面的代码输出以下内容:
我想在顶部有一个合并的单元格,该单元格是居中对齐的,左列是右对齐的,而右列是左对齐的。左列将从MySQL查询中获取字符串,并替换“ Box#”字符串,如下所示:
问题:您能否实现我的代码,该代码将:
在kivys GridLayout中,没有连接单元的功能。但是您可以解决此问题,使其看起来像这样。
在猕猴桃中,很容易组合布局。并且您可以根据需要嵌套它们,
因此,其中有2个元素的垂直boxlayout可能是解决此问题的方法。
vertical BoxLayout
Head Label
GridLayout
我会在这里给你看一个例子。
python文件只是一个最小的应用程序。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_file("kv.kv")
class RemoveScreen(BoxLayout):
pass
class MyApp(App):
def build(self):
return RemoveScreen()
MyApp().run()
还有kv.kv文件。为了使代码更整洁,我制作了自定义Label类。这样,您只需要在一个位置更改值即可。
<MyLabel1@Label>:
font_size: "20sp"
bold: True
color: [1,1,0,1]
halign: "right"
text_size: root.width, None
size: self.texture_size
<MyLabel2@Label>:
halign: "left"
text_size: root.width, None
size: self.texture_size
<RemoveScreen>:
orientation: "vertical"
MyLabel1:
text: "Headline"
size_hint: (1,0.05)
halign: "center"
GridLayout:
rows: 6
cols: 2
padding: [0, 0, 0, 25]
spacing: [10,0]
MyLabel1:
text: "Part number:"
MyLabel2:
text: "Box 02"
MyLabel1:
text: "Part description:"
MyLabel2:
text: "Box 04"
MyLabel1:
text: "Quatity on hand:"
MyLabel2:
text: "Box 06"
MyLabel1:
text: "Bin location:"
MyLabel2:
text: "Box 08"
MyLabel1:
text: "Direction:"
MyLabel2:
text: "Box 10"
MyLabel1:
text: "Scan time:"
MyLabel2:
text: "Box 12"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句