Here is the relevant snippet of my mykv.kv file:
:
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
The code above outputs this:
I would like to have a merged cell on top, where it is center justified,the left column be right justified, and the right column be left justified. the left column will obtain the strings from a MySQL query, and replace the "Box #" strings, looking like:
Questions:
Could you please implement in to my code that will:
Merge the first row of two cells into one
Right justify the left column
Left justify the right column (as per the layout above)
解决方案
In kivys GridLayout, there is no feature to join cells.
But you could do a work around this, to make it look like that.
In kivy it is easy to combine layouts. And you can nest them as much as you want
So a vertical boxlayout, with 2 elements in it, could be the workaround for this problem.
vertical BoxLayout
Head Label
GridLayout
I will show you an example here.
The python file is just a minimal app.
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()
And the kv.kv file. To make the code cleaner, I made custom Label classes. That way you only need to change values at one place.
:
font_size: "20sp"
bold: True
color: [1,1,0,1]
halign: "right"
text_size: root.width, None
size: self.texture_size
:
halign: "left"
text_size: root.width, None
size: self.texture_size
:
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"