第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何讓多個(gè)小部件按鈕在 Jupyter Notebook 中執(zhí)行不同的操作?

如何讓多個(gè)小部件按鈕在 Jupyter Notebook 中執(zhí)行不同的操作?

慕村225694 2022-05-19 18:30:37
我正在嘗試制作一系列按鈕,這些按鈕根據(jù)某些場(chǎng)景從數(shù)據(jù)集中獲取樣本。我有一組 3x2 的按鈕,每個(gè)按鈕描述不同的場(chǎng)景。我似乎無法讓他們執(zhí)行各自的操作。我想我了解如何將單擊按鈕的操作與其響應(yīng)聯(lián)系起來。但是,我不明白如何為多個(gè)按鈕做同樣的事情。這是我的代碼,它可以讓一個(gè)獨(dú)立的按鈕工作:button = widgets.Button(description='Generate message!')out = widgets.Output()def on_button_clicked(_):    samp_text = raw_data.sample(1).column(1)    # "linking function with output"    with out:      # what happens when we press the button      print(samp_text)# linking button and function together using a button's methodbutton.on_click(on_button_clicked)# displaying button and its output togetherwidgets.VBox([button,out])現(xiàn)在我要做的是在不同的情況下采取不同類型的樣本。因此,我為每種返回比例表的采樣方法編寫了函數(shù):1    47.7393622    44.6808513     4.9202139     2.659574Name: vote, dtype: float64但是,第一個(gè)示例中只有一個(gè)按鈕的相同方法不適用于多個(gè)按鈕。如何使用 widgets.Output() 以及如何連接它以便單擊按鈕輸出相應(yīng)的示例摘要?我希望單擊的按鈕能夠輸出其示例摘要,如上所示。
查看完整描述

2 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

擴(kuò)展您的示例以使用多個(gè)按鈕我沒有任何問題。我不知道你在哪里困惑。

http://img1.sycdn.imooc.com//62861c6a0001543210961045.jpg

有時(shí),小部件回調(diào)中發(fā)生的異常不會(huì)被打印出來——也許您的代碼中有一個(gè)錯(cuò)誤,因此您看不到。最好將所有內(nèi)容都包裹在“with out:”中



查看完整回答
反對(duì) 回復(fù) 2022-05-19
?
尚方寶劍之說

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊

使用列表創(chuàng)建了兩個(gè)按鈕。猜測(cè)代碼本身解釋得更好。


from ipywidgets import Button, HBox


thisandthat = ['ON', 'OFF']


switch = [Button(description=name) for name in thisandthat]


combined = HBox([items for items in switch])


def upon_clicked(btn):

    print(f'The circuit is {btn.description}.', end='\x1b\r')

    for n in range(len(thisandthat)):

        switch[n].style.button_color = 'gray'

    btn.style.button_color = 'pink'


for n in range(len(thisandthat)):

    switch[n].on_click(upon_clicked)


display(combined)


查看完整回答
反對(duì) 回復(fù) 2022-05-19
  • 2 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)