合并单元格导入mysql,Kivy:如何合并单元格并与MySQL数据库交互

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:

3IuVf.png

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:

x5PHY.png

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"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值