113113 ], className = "mt-2" ),
114114
115115 html .Div (children = [
116- dbc .Alert ("primary!" , color = "primary" , id = "alert_memory " ),
117- dbc .Alert ("secondary!" , color = "secondary" , id = "alert_local " ),
118- dbc .Alert ("success!" , color = "success" , id = "alert_session " ),
116+ dbc .Alert ("primary!" , color = "primary" , id = "alert-memory " ),
117+ dbc .Alert ("secondary!" , color = "secondary" , id = "alert-local " ),
118+ dbc .Alert ("success!" , color = "success" , id = "alert-session " ),
119119 dbc .Alert ("info!" , color = "info" ),
120120 dbc .Alert ("warning!" , color = "warning" ),
121- dbc .Alert ("danger!" , color = "danger" ),
121+ dbc .Alert ("danger!" , color = "danger" , id = "alert-danger" , is_open = True , fade = True ),
122122 ], className = "mt-2" ),
123123
124124 # 按钮类 ========================================================================================
125125 html .Div (children = [
126- dbc .Button ("primary" , color = "primary" , className = "mr-2" , id = "button_memory " ),
127- dbc .Button ("secondary" , color = "secondary" , className = "mr-2" , id = "button_local " ),
128- dbc .Button ("success" , color = "success" , className = "mr-2" , id = "button_session " ),
126+ dbc .Button ("primary" , color = "primary" , className = "mr-2" , id = "button-memory " ),
127+ dbc .Button ("secondary" , color = "secondary" , className = "mr-2" , id = "button-local " ),
128+ dbc .Button ("success" , color = "success" , className = "mr-2" , id = "button-session " ),
129129 dbc .Button ("info" , color = "info" , className = "mr-2" ),
130130 dbc .Button ("warning" , color = "warning" , className = "mr-2" ),
131- dbc .Button ("danger" , color = "danger" , className = "mr-2" ),
131+ dbc .Button ("danger" , color = "danger" , className = "mr-2" , id = "button-danger" ),
132132 dbc .Button ("primary" , color = "primary" , className = "mr-2" , size = "sm" , outline = True ),
133133 dbc .Button ("secondary" , color = "secondary" , className = "mr-2" , size = "md" , outline = True ),
134134 dbc .Button ("success" , color = "success" , className = "mr-2" , size = "lg" , outline = True ),
177177 ], className = "mt-2" ),
178178
179179 html .Div (children = dcc .ConfirmDialogProvider (
180- id = "confirm" ,
180+ # id="confirm",
181181 children = dbc .Button ("ConfirmDialogProvider" , color = "primary" ),
182182 message = "Danger danger! Are you sure you want to continue?"
183183 ), className = "mt-2" ),
319319# 创建回调函数:回调函数中不能出现全局变量
320320for store in ("memory" , "local" , "session" ):
321321 @app .callback (Output (store , "data" ), [
322- Input ("button_ %s" % store , "n_clicks" )
322+ Input ("button- %s" % store , "n_clicks" )
323323 ], [
324324 State (store , "data" ),
325325 State (store , "modified_timestamp" ),
@@ -332,7 +332,7 @@ def toggle_store_button(n_clicks, data, ts):
332332 data ["ts" ] = ts
333333 return data
334334
335- @app .callback (Output ("alert_ %s" % store , "children" ), [
335+ @app .callback (Output ("alert- %s" % store , "children" ), [
336336 Input (store , "modified_timestamp" )
337337 ], [
338338 State (store , "data" ),
@@ -345,13 +345,24 @@ def toggle_store_change(ts, data, name):
345345 return "%s: %s, ts=%s" % (name , data ["clicks" ], data ["ts" ])
346346
347347
348+ @app .callback (Output ("alert-danger" , "is_open" ), [
349+ Input ("button-danger" , "n_clicks" )
350+ ], [
351+ State ("alert-danger" , "is_open" )
352+ ])
353+ def toggle_danger_button (n_clicks , is_open ):
354+ if n_clicks :
355+ return not is_open
356+ return is_open
357+
358+
348359@app .callback (Output ("collapse" , "is_open" ), [
349360 Input ("collapse-button" , "n_clicks" )
350361], [
351362 State ("collapse" , "is_open" )
352363])
353- def toggle_collapse (n , is_open ):
354- if n :
364+ def toggle_collapse (n_clicks , is_open ):
365+ if n_clicks :
355366 return not is_open
356367 return is_open
357368
@@ -389,4 +400,4 @@ def advance_progress(n):
389400 Input ("progress" , "value" ),
390401])
391402def advance_text (value ):
392- return "Processtext : %d" % value
403+ return "Process-text : %d" % value
0 commit comments