我需要編寫一個函數,它知道單擊了哪個按鈕來調用它。我正在使用 ipywidgets 和 jupyter notebook。這是一些示例代碼:import ipywidgets as widgetsbutton1 = widgets.Button(description = 'I am button 1')button2 = widgets.Button(description = 'I am button 2')def self_aware(caller): # Some code I don't know pass button1.on_click(self_aware)button2.on_click(self_aware)widgets.VBox([button1, button2])單擊時,按鈕 1 應作為參數傳遞給函數self_aware。例如 justprint('I am button 1')或 2 就足夠了
添加回答
舉報
0/150
提交
取消