Kivy - base application has strange alignment(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.
Press 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.
这就是我所看到的......
here is what I am seeing..
推荐答案
由于你的根小部件不是布局(你让 SublimeLauncher
继承 Widget
),它不会't 设置其子级大小/位置.所以你的 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 - 基础应用程序有奇怪的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Kivy - 基础应用程序有奇怪的对齐方式
基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01