это мой код: main.py
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.textinput import TextInput
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock
from kivy.uix.gridlayout import GridLayout
import numpy as np
Window.clearcolor = (0.5, 0.5, 0.5, 1)
Builder.load_file('MyMain.kv')
class MainWindow(GridLayout):
def __init__(self, **kwargs):
super(MainWindow, self).__init__(**kwargs)
Window.bind(on_key_down=self._on_keyboard_down)
self.counter = 1
Clock.schedule_once(self.add_stuff)
def add_stuff(self, *args):
self.textlist = [TextInput()]
self.ids.grid.add_widget(Label(text='% Gas {} '.format(self.counter)))
self.counter += 1
self.ids.grid.add_widget(self.textlist[0])
def addnewtextinput(self):
self.ids.grid.add_widget(Label(text='% Gas ' + str(self.counter)))
self.counter += 1
self.textlist.append(TextInput())
self.ids.grid.add_widget(self.textlist[-1])
def _on_keyboard_down(self, instance, keyboard, keycode, text, modifiers):
if keyboard == 13: # 32 - Cpace key presssed Ascii
self.getresult()
if keyboard == 9 : # 13 - Enter key presssed Ascii
self.addnewtextinput()
b = [i.text.strip().split(" ") for i in self.textlist]
X = [[int(y) for y in x] for x in b]
for i in range(len(X)-1):
)
if (len(X[i]) < len(X[i+1])):
for _ in range(len(X[i+1]) - len(X[i])):
X[i].append(0)
if (len(X[i+1]) < len(X[i])):
for _ in range(len(X[i]) - len(X[i+1])):
X[i+1].append(0)
print(X[i])
print(X) # this is the Dynamic Array
class TextInput(TextInput):
def __init__(self, **kwargs):
super(TextInput, self).__init__(**kwargs)
def set_focus(dt):
self.focus = True
Clock.schedule_once(set_focus, .1)
class MyMainApp(App):
def build(self):
return MainWindow()
if __name__ == "__main__":
MyMainApp().run()
MyMain.kv
<CustButton@Button>:
font_size: 40
<MainWindow>:
spacing : 10
name: "erst"
grid: grid.__self__
rows:2
cols:1
GridLayout:
orientation: "horizon"
padding: 2
id:grid
cols:2
<TextInputX>
focus: True
Список X - это список Dynami c, как я могу сделать Dynami c GridLayout с гибкими столбцами и рядами?