Python 使用 for 循环输入短划线,并通过发送行数、列数和矩阵作为参数

Python Dash input with for loop and by sending the number of rows, columns and matrix as parameters

我想通过发送行数、列数和矩阵数来创建带有 for 循环的输入 parameters.I 写的是代码 below.Where 我做错了吗(我想创建输入如图中的盒子)

matris_toplam = html.Div([
    html.Div(
        [html.Hr(), 
            html.Label('Matrix Row Number'),
            html.Br(),
            dcc.Input(id='msatir', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Satır Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Column Sayısı'),
            html.Br(),
            dcc.Input(id='msutun', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sütun Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Number'),
            html.Br(),
            dcc.Input(id='msayi', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sayısı', href=''),
            html.Br(),


        ],
        className='mt-2 ml-2',
    ),

])

def matrixbox(row,col,sayi):
    b=row*col*sayi
    return [dcc.Input(type='text', id='input%i' % i)for i in range(b)]

@app.callback(
    [dash.dependencies.Output('input%i' %i, 'children')for i in range(row*col*sayi)],
    [Input("msatir", "value"),Input("msutun", "value"),Input("msayi", "value")],
    
)

def update_output(row,col,sayi):
    if row != None and col != None and sayi != None:
        a=matrixbox(row,col,sayi)
        return '{}'.format(a)

我会为你做造型:)。这应该有效。

from dash import Dash, html, dcc
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc


app = Dash(__name__)

app.layout =  html.Div([
    html.Div(
        [html.Hr(), 
            html.Label('Matrix Row Number'),
            html.Br(),
            dcc.Input(id='msatir', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Satır Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Column Sayısı'),
            html.Br(),
            dcc.Input(id='msutun', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sütun Sayısı', href=''),
            html.Br(),
            html.Label('Matrix Number'),
            html.Br(),
            dcc.Input(id='msayi', type='number',
                      style={'textAlign': 'center', 'width': 'auto'}),
            html.A('          [ ? ]', title='Toplanacak Matrislerin Sayısı', href=''),
            html.Br(),
            

        ],
        className='mt-2 ml-2',
    ),
    html.Div(id='container', style={'display':'flex'})

])

@app.callback(
    Output('container', 'children'),
    [Input("msatir", "value"),Input("msutun", "value"),Input("msayi", "value")],
    
)


def update_output(row,col,sayi):
    final = []
    lst = list()
    if row != None and col != None and sayi != None:
        for k in range(sayi+1):
            
            if k != sayi:
                for i in range(col):
                    lst.append(dbc.Row([dbc.Col(dbc.Input(type='number', id=f'input{k}{j}{i}',
                                        style={'textAlign': 'center','placeholder':'input'})) for j in range(row)]))
            else:
                for i in range(col):
                    lst.append(dbc.Row([dbc.Col(dbc.Input(type='text', id=f'input{k}{j}{i}',placeholder='output',
                                        style={'textAlign': 'center', 'border': '1px solid #588BAE'})) for j in range(row)]))

            final.append(html.Div(lst,style={'display': 'flex','margin-right': '40px'}))
            
            lst = []
        
        return final

if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)