简体   繁体   English

多屏Kivy FloatLayout

[英]Kivy FloatLayout in multiple screens

The FLoatLayout in kivy seems to restricted to only one screen per time. kivy 中的 FLoatLayout 似乎每次仅限于一个屏幕。 I want to use multiple screens and apply FloatLayout on all of them.我想使用多个屏幕并在所有屏幕上应用 FloatLayout。

What I have tried:我试过的:

  1. I know I can separate all the screens into different kivy and python files then combine them, but I don't want to because of ease of use.我知道我可以将所有屏幕分成不同的 kivy 和 python 文件,然后将它们组合起来,但由于易于使用,我不想这样做。
  2. I tried allowing my classes (Screens) to inherit from both screen and FloatLayout, but apparently the ScreenManager does not accept 'non-screen inputs'我尝试允许我的类(屏幕)从屏幕和 FloatLayout 继承,但显然 ScreenManager 不接受“非屏幕输入”
  3. I am using kivy Language, (not python) so I can not just assign widgets to the FloatLayout inside a window class then return it.我正在使用 kivy 语言,(不是 python)所以我不能只将小部件分配给 window class 内的 FloatLayout 然后返回它。

ps.附言。 The reason I want to use FloatLayout is to avoid overlapping widgets.我想使用 FloatLayout 的原因是避免重叠的小部件。 I wouldn't mind using another layout if it produces a similar result.如果它产生类似的结果,我不介意使用另一种布局。

You can add another layout in your screen like this (in the kv part of the code):您可以像这样在屏幕中添加另一个布局(在代码的 kv 部分中):

    ScreenManager:
        id: screens
        Screen:
            name: "main"
            id: main
            BoxLayout:
                id: main_box

You can do something similar in the python part of the code by using:您可以使用以下代码在代码的 python 部分中执行类似的操作:

main_box = BoxLayout()
self.ids.main.add_widget(main_box)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM