避免因Kivy中的动态调整大小而引起的重叠

时间:2018-10-08 01:32:22

标签: python user-interface layout kivy

我正在研究一种GridLayout(在这里称为CostosInput),当按下按钮时,它会向自身添加TextInputs。但是,这样做时,布局不会调整其周围小部件的大小,一旦添加了一定数量的TextInput小部件,该布局便会重叠。我该如何解决?

它是另一个GridLayout的一部分,该ScrollView具有一列并包含在Label中。它下面的小部件(与之重叠的小部件)是Layouts

我尝试查看Kivy文档,但发现的唯一内容与Widgetslayout_hint_with_bounds(sh_sum, available_space, min_bounded_size, sh_min_vals, sh_max_vals, hint)的大小有关,而不一定与它们的位置有关。我以为它类似于CostoInput (link to the Kivy docs),但这是一个内部函数。如果某些不符合约定,我深表歉意。

这是class CostosInput(GridLayout): def __init__(self, *args, **kwargs): super(CostosInput, self).__init__() self.cols = 2 self.spacing = 5 self.padding = 5 self.size_hint_y = 0.2 # used in add_lines() self.count = 1 add = Orange_Button(text='AGREGAR COSTO') add.bind(on_press=self.add_lines) rem = Orange_Button(text='QUITAR COSTO') rem.bind(on_press=self.del_lines) self.add_widget(add) self.add_widget(rem) self.add_widget(Orange_Label(text='concepto')) self.add_widget(Orange_Label(text='costo')) self.add_lines() # this function is adds TextInputs # when the add button is pressed def add_lines(self, *args, **kwargs): text = Normal_TI() text.text = 'costo ' + str(self.count) text.bind(text=self.change) flot = FloatInput() flot.bind(text=self.change) self.add_widget(text) self.add_widget(flot) self.size_hint_y += 0.1 self.count += 1 # this has nothing to do with the ui def del_lines(self, *args, **kwargs): for x in range(0, len(self.children) - 4, 2): if len(self.children) > 4: try: if self.children[x].focus or self.children[x + 1].focus: self.remove_widget(self.children[x]) self.remove_widget(self.children[x]) except Exception as err: print('del lines: no se pudieron quitar,' 'err {}'.format(err)) # this also has nothing to do with the ui def change(self, value, *args): dicto = dict() for x in range(0, len(self.children) - 4, 2): dicto[self.children[x + 1].text] = self.children[x].text print(dicto) producto.costos = dicto 类的代码。

class Orange_Label(Label):
def __init__(self, *args, **kwargs):
    super(Orange_Label, self).__init__(*args, **kwargs)
    self.size_hint_y = None
    self.size = (self.width, 10)
    self.color = (0.95668627451, 0.6941176471, 0.5137254902, 1)

这是实例化标签的类的代码。文本属性是唯一更改的部分。

onClick={()=> this.render_detail_options(share, model)}.

0 个答案:

没有答案