I’m trying to create a keypad entry interface that based on the buttons pressed it generates and displays a four digit number. The interface part is easy but rather than displaying the number based on the buttons pressed it always defaults to “1234” after pressing enter. Below is the code block. Any ideas how to get it to show, for example 2500, if I press the “2”, “5” and “0” buttons twice?
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash import html
from dash.dependencies import Input, Output, State
app = dash.Dash()
app.layout = html.Div([
html.Div([
html.Button(id=‘button-7’, value=‘7’, children=‘7’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-8’, value=‘8’, children=‘8’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-9’, value=‘9’, children=‘9’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’})
], style={‘display’: ‘flex’}),
html.Div([
html.Button(id=‘button-4’, value=‘4’, children=‘4’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-5’, value=‘5’, children=‘5’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-6’, value=‘6’, children=‘6’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’})
], style={‘display’: ‘flex’}),
html.Div([
html.Button(id=‘button-1’, value=‘1’, children=‘1’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-2’, value=‘2’, children=‘2’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-3’, value=‘3’, children=‘3’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’})
], style={‘display’: ‘flex’}),
html.Div([
html.Button(id=‘button-0’, value=‘0’, children=‘0’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-00’, value=‘00’, children=‘00’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
html.Button(id=‘button-enter’, n_clicks=0, children=‘Enter’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’})
], style={‘display’: ‘flex’}),
html.Div([
html.Output(id=‘output’, style={‘fontSize’:48, ‘width’: ‘66%’, ‘height’: ‘60px’}),
html.Button(‘Reset’, id=‘button-reset’, style={‘fontSize’:24, ‘width’: ‘33%’, ‘height’: ‘60px’}),
], style={‘display’: ‘flex’}),
])
@app.callback(
Output(‘output’, ‘children’),
[Input(‘button-1’, ‘value’),
Input(‘button-2’, ‘value’),
Input(‘button-3’, ‘value’),
Input(‘button-4’, ‘value’),
Input(‘button-5’, ‘value’),
Input(‘button-6’, ‘value’),
Input(‘button-7’, ‘value’),
Input(‘button-8’, ‘value’),
Input(‘button-9’, ‘value’),
Input(‘button-0’, ‘value’),
Input(‘button-enter’, ‘n_clicks’)])
def update_output(b1, b2, b3, b4, b5, b6, b7, b8, b9, b0, enter):
if enter > 0:
return b1 + b2 + b3 + b4
else:
return ‘’
if name == ‘main’:
app.run_server()