Python:Kivy:如何对齐标签本身和文本框?

哈希姆

我从这里尝试了多段代码,但它们似乎都在标签或文本框中对齐文本。我想垂直和水平对齐文本框和标签。我是 kivy 的初学者,所以如果答案很明显,请原谅。

  1. 有没有办法对齐标签本身而不是里面的文本?
  2. 还有一种方法可以对齐文本框本身而不是里面的文本吗?

提前致谢!

这是我的 .kv 文件firstkivy.kv

#Filename: firskivy.kv

<MyGrid>:
    Label:
        text: "Writing"
        font_size: 80
        bold: True
        color: 0.204, 0.204, 0.204, 1
        size: self.texture_size
        text_size: self.size
        halign: 'center'
        valign:'middle'
        canvas.before:
            Color:
                rgba: 0.549, 1, 0.984, 1
            Rectangle:
                size: self.size
                pos: self.pos


    TextInput:
        size_hint: (.2, None)
        height: 100
        width: 360
        multiline: True
        size_hint: (None, None)
        font_size: 30
        halign: 'right'
        pos_hint: (None, None)
        focus: True

这是 .py 文件firstkivy.py

# setting up and fixing the window size
#to prevent it from being resized
from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics','width', '360')
Config.set('graphics', 'height', '540')

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window

# going back to this one...
Window.clearcolor = (0.549, 1, 0.984, 1)

class MyApp(Widget):
    pass

#building the app
class FirstKivy(App, BoxLayout):
    def build(self):

        self.title = 'Arabic Language Learning App'
        return MyApp()

# running the app
if __name__ == '__main__':
    FirstKivy().run()

这是 输出

帕科·莫阿罗

尝试这样写firstkivy.py

from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics','width', '360')
Config.set('graphics', 'height', '540')

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window


class MyApp(BoxLayout):
    pass


class FirstKivy(App):
    title = 'Arabic Language Learning App'
    def build(self):

        return MyApp()


if __name__ == '__main__':
    FirstKivy().run

还有你firstkivy.kv喜欢的:

<MyApp>:
    orientation: "vertical"
    spacing: 10
    space_x: self.size[0]/3
    canvas.before:
        Color:
            rgba: 0.549, 1, 0.984, 1
        Rectangle:
            size: self.size
            pos: self.pos

    FloatLayout:

        Label:
            text: "Writing"
            font_size: 80
            bold: True
            color: 0.204, 0.204, 0.204, 1
            pos_hint: {'center_x': .5, 'center_y': .8}
            #size: self.texture_size
            #text_size: self.size
            #halign: 'center'
            #valign:'middle'


        TextInput:
            size_hint: 1, .5
            #height: 100
            #width: 200
            multiline: True
            pos_hint: {'center_x': .5}
            #size_hint: None, None
            #font_size: 30
            #halign: 'right'
            #pos_hint: None, None
            #focus: True

希望它能达到你想要的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章