KivyPython文本输入框填充整个浮动布局屏幕

2024-10-01 19:33:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Kivy中遇到一个TextInput问题。在

当我将它添加到我的一个屏幕上现有的FloatLayout时,它会占用整个窗口,即使指定了高度。我希望将此文件保存在.py文件中,因此请避免在.kv文件中添加任何用于调整大小的样式选项。在

class WebsiteInput(Screen):
    def __init__(self, **kwargs):
        super(WebsiteInput, self).__init__(**kwargs)
        Clock.schedule_once(self._finish_init)

    def _finish_init(self, dt):
        # Title Label
        self.lbl1 = Label(text="Enter a URL to bind to this button:", pos=(self.x, self.height +132))
        self.lbl1.font_name = 'Montserrat-Bold.ttf'
        self.lbl1.font_size = 28
        self.ids.float_web.add_widget(self.lbl1)
        # URL Text Input
        self.web_input = TextInput(height=100)
        self.web_input.height = 100
        self.ids.float_web.add_widget(self.web_input)

如你所见,我已经尝试在两个不同的位置影响大小,它仍然填充了整个窗口。在


Tags: 文件toselfweburlinputinitdef
1条回答
网友
1楼 · 发布于 2024-10-01 19:33:12

为了使size属性生效,您需要^{}属性在相应的轴上是None

class WebsiteInput(Screen):
    def __init__(self, **kwargs):
        super(WebsiteInput, self).__init__(**kwargs)
        Clock.schedule_once(self._finish_init)

    def _finish_init(self, dt):
        # Title Label
        self.lbl1 = Label(text="Enter a URL to bind to this button:",
                          pos=(self.x, self.height +132))
        self.lbl1.font_name = 'Montserrat-Bold.ttf'
        self.lbl1.font_size = 28
        self.ids.float_web.add_widget(self.lbl1)
        # URL Text Input
        self.web_input = TextInput(height=100, 
                                   size_hint = (1,  None))
        self.ids.float_web.add_widget(self.web_input)

相关问题 更多 >

    热门问题