基本应用程序具有奇怪的对齐方式

基本应用程序具有奇怪的对齐方式

本文介绍了Kivy-基本应用程序具有奇怪的对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建基本的Kivy应用.添加基本​​元素并运行应用程序后,所有元素都塞入左下角.它在Android和Linux上显示如下.

I am trying to build a basic Kivy app. After adding the basic elements, and running the app, all of the elements are crammed into the bottom left corner. It shows up like this on android and Linux.

Main.py:

from kivy.app import App
from kivy.uix.widget import Widget

class SublimeLauncher(Widget):
    pass

class SublimeLauncherApp(App):
    def build(self):
        return SublimeLauncher()

if __name__ == "__main__":
    SublimeLauncherApp().run()

sublimelauncher.kv:

sublimelauncher.kv:

#:kivy 1.2.0
<SublimeLauncher>:
    FloatLayout:
        BoxLayout:
            orientation: 'vertical'
            spacing: 10
            Label:
                text: "Enter the path to the folder to open.\nPress OK if you would like to open without a directory"
            TextInput:
                id: folderpath
            Button:
                text: 'OK'

我首先仅使用BoxLayout进行了尝试,但是在某个地方读取根窗口小部件总是和应用程序一样大.如何声明应用程序的大小?还是布局?您将如何做类似对话框的事情?

I first tried it with just the BoxLayout, but read somewhere the root widget is always as big as the app. How do I declare the size of the app? Or the layout? How would you go about doing something like a dialog box?

也许我缺少一些非常基本的东西,但是我似乎无法弄清楚.

Maybe I am missing something very basic, but I can't seem to figure it out.

这就是我所看到的.

推荐答案

由于您的根窗口小部件不是布局(您使SublimeLauncher继承了Widget),因此它不会设置其子级的大小/位置.因此,您的FloatLayout具有默认值,因为您也不会手动覆盖它们.

As your root widget is not a layout (you made SublimeLauncher inherit Widget), it doesn't set its children size/positions. So your FloatLayout have the defaults, since you don't override them manually either.

pos: 0, 0
size: 100, 100

这些默认值当然会约束子级,因为FloatLayout通过基于其size_hint属性来约束其大小.

And these defaults of course constraints the child, since FloatLayout by constraint their size based on their size_hint property.

正如Nykakin所指出的,您想给他们更多的空间.

You want to give them more space, as Nykakin pointed out.

另外,由于您的文本大于标签(您也未设置halign和text_size),因此其纹理位于标签中心,因此部分内容不在屏幕上.您想看看kivy/examples/widgets/textalign.py

Also, as your text is bigger than the Label (you didn't set halign and text_size either) its texture is centered on the center of the Label, and so some part of it is out of screen. You want to have a look at kivy/examples/widgets/textalign.py

这篇关于Kivy-基本应用程序具有奇怪的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:38