kivy:当我调整窗口大小时,FloatLayout小部件不会更新其位置/大小

时间:2016-10-13 10:24:43

标签: layout resize widget window kivy

在我的练习中,当我调整窗口大小时,小部件“TextInput”不会更新其位置和大小;相反,小部件“标签”正确更新其大小和位置。为什么?有谁可以帮助我吗?

from kivy.app import App

from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.graphics import Color, Rectangle



class MyWidget(FloatLayout):
    def __init__(self, *args):
        super(MyWidget, self).__init__(*args)



        with self.canvas.before:
            Color(255, 255, 255, 1) 
            self.rect = Rectangle(size=self.size, pos=self.pos)

        def update_rect(instance, value):
            instance.rect.pos = instance.pos
            instance.rect.size = instance.size


        self.bind(pos=update_rect, size=update_rect)



        self.add_widget(TextInput(text='InsertText', multiline=False, size_hint=(1, 0.04),
                                  pos_hint={'right': 1, 'y': 0.879}, font_size='12sp'))

        self.add_widget(Label(text='label example', color=(0,0,255,0.5), pos_hint={'center_x': 0.5, 'center_y': 0.5}))






class MyApp(App):
    def build(self):

        return MyWidget()


if __name__ == '__main__':
    MyApp().run()

0 个答案:

没有答案