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

问题描述 投票:0回答:1

我从这里尝试了多段代码,但是它们似乎都使标签或文本框中的文本对齐。我想垂直和水平对齐文本框和标签。我是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()

这里是Output

python alignment kivy kivy-language
1个回答
0
投票

尝试像这样写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

希望它可以实现您想要的。

© www.soinside.com 2019 - 2024. All rights reserved.