Kivy内容大小调整

时间:2018-06-26 09:45:35

标签: python kivy kivy-language

我最近开始从事奇异果工作。我现在正在做的是,我有一个带按钮的空白页面,当我单击该按钮时,它将导航到用户输入屏幕。它可以正常工作,但是内容在一个很小的输入框和文本中出现,如图所示。

here

我的问题是我希望它更大且更中心。

这是我的代码:

在python中:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.widget import Widget
from kivy.lang import Builder

class LoginScreen(GridLayout):
    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text="Username:"))
        self.username = TextInput(multiline=False)
        self.add_widget(self.username)

        self.add_widget(Label(text="Password:"))
        self.password = TextInput(multiline=False, password=True)
        self.add_widget(self.password)

        self.add_widget(Label(text="Two Factor Auth:"))
        self.tfa = TextInput(multiline=False)
        self.add_widget(self.tfa)

class MainScreen(Screen):
    pass

class AnotherScreen(Screen):
    pass

class ScreenManagement(ScreenManager):
    pass

presentation = Builder.load_file("screen.kv")   

class SimpleKivy(App):
    def build(self):
        return presentation

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

在kv中:

 #: import FadeTransition kivy.uix.screenmanager.FadeTransition

ScreenManagement:
    transition: FadeTransition()
    MainScreen:
    AnotherScreen:

<MainScreen>:
    name: "main"
    Button:
        color: 0,1,0,1
        font_size: 25
        size_hint: 0.3,0.2
        text: "Click"
        on_release: app.root.current = "other" 
        pos_hint: {"right":1, "top":1}      


<AnotherScreen>:
    name: "other"

    GridLayout:
        LoginScreen

1 个答案:

答案 0 :(得分:1)

screen.kv中,您将LoginScreen放在GridLayout中。由于LoginSCreenGridLayout,因此您不需要多余的GridLayout

只需更改:

<AnotherScreen>:
    name: "other"

    GridLayout:
        LoginScreen

收件人:

<AnotherScreen>:
    name: "other"

    LoginScreen: