如何在kivy中动态调整窗口大小?

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

我在桌面应用程序构建期间遇到了问题,因为在不同的屏幕中我需要不同的窗口大小(如登录,菜单等)我需要做什么?

python window kivy size
1个回答
0
投票

您可以在屏幕on_pre_enter事件中更改窗口大小。在切换屏幕时更改窗口大小时,最好不要进行转换。 试试这个例子:

from kivy.app import App
from kivy.lang import Builder


KV = """
#:import Window kivy.core.window.Window
#:import NoTransition kivy.uix.screenmanager.NoTransition

ScreenManager:
    transition: NoTransition()
    Screen:
        on_pre_enter:
            Window.size = (400, 400)
        name: "scr1"
        Button:
            font_size: "40sp"
            text: "Next screen"
            on_release:
                root.current = "scr2"
    Screen:
        on_pre_enter:
            Window.size = (200, 50)
        name: "scr2"
        Button:
            font_size: "20sp"
            text: "Previous screen"
            on_release:
                root.current = "scr1"

"""


class MyApp(App):
    def build(self):
        return Builder.load_string(KV)

MyApp().run()
© www.soinside.com 2019 - 2024. All rights reserved.