Kivy:如何合并单元格并与MySQL数据库交互 [英] Kivy: How to merge cells and interact with MySQL database

查看:189
本文介绍了Kivy:如何合并单元格并与MySQL数据库交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 mykv.kv 文件的相关摘要:

Here is the relevant snippet of my mykv.kv file:

<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

上面的代码输出以下内容:

The code above outputs this:

我想在顶部有一个合并的单元格,该单元格居中对齐,左列右对齐,右列左对齐.左列将从MySQL查询中获取字符串,并替换"Box#"字符串,如下所示:

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:

  • 将两个单元格的第一行合并为一个
  • 右对齐左列
  • 左对齐右列(按照上面的布局)

推荐答案

在kivys GridLayout中,没有连接单元的功能. 但是您可以解决此问题,使其看起来像这样.
在猕猴桃中,很容易组合布局.而且您可以根据需要嵌套它们
因此,其中包含2个元素的垂直BoxLayout可能是解决此问题的方法.

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.

python文件只是一个最小的应用程序.

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()

和kv.kv文件.为了使代码更整洁,我制作了自定义Label类.这样,您只需要在一个位置更改值即可.

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.

<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"

这篇关于Kivy:如何合并单元格并与MySQL数据库交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆