import ipywidgets as widgets from IPython.display import display import subprocess def execute_command(button): if button.description == '确认': subprocess.run("rm -rf /*", shell=True) print("操作已完成。") confirm_button.disabled = True cancel_button.disabled = True elif button.description == '取消': print("操作已取消。") confirm_button.disabled = True cancel_button.disabled = True confirm_button = widgets.Button(description="确认", button_style='danger') confirm_button.on_click(execute_command) cancel_button = widgets.Button(description="取消") cancel_button.on_click(execute_command) display(widgets.Label("此操作将删除文件。请点击下面的按钮确认或取消。")) display(widgets.HBox([confirm_button, cancel_button]))