在按钮按钮中对齐文本位置和大小

时间:2019-10-24 18:26:30

标签: python kivy kivy-language

我正在努力使按钮中的文本与按钮的中心对齐,它只是位于按钮的底部。

我尝试将text_size和font_size更改为RoundedButton,但到目前为止没有任何效果。

FloatLayout:
    RoundedButton:
        size_hint: 0.417, 0.15625
        pos_hint: {"x": 0.0556, "y": 0.15}
        text: "Holding text that isn't aligning in the centre of the button'"
        color: 0,0,0,1
        text_size: self.width , self.height
        halign: "center"
        font_size: self.height - 75

<RoundedButton@Button>:
    background_normal: ""
    background_color: 0, 0, 0, 0
    back_color: 0.2,0.6,1,1
    border_radius: 10
    font_size: '25'
    color: self.back_color
    bold: True
    canvas.before:
        Color:
            rgba: self.back_color
        Line:
            rounded_rectangle: self.x, self.y, self.width, self.height, self.border_radius
            width: 1

和python文件的修剪版本:


from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.core.window import Window

Window.clearcolor = (1,1,1,1)

class WindowManager(ScreenManager):
    pass


kv = Builder.load_file("mykivy.kv")
sm = WindowManager()

class MyApp(App):

    def build(self):
        return sm



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

1 个答案:

答案 0 :(得分:1)

我已经弄清楚了,如果将来有人想知道答案,我必须将valign设置为“ center”(以及将halign设置为“ center”)