简体   繁体   中英

Python, Bokeh - my button won't do ANYTHING

Python 3.6 and Bokeh 0.12.16.

No matter what I change the body of the onclick() function to - it doesn't do anything! I can't even verify if it's being called or not.

button = Button(label='Update', button_type='primary')
button.on_click(onclick)

p = Paragraph(text='aaaaaaa',
width=200, height=100)

def onclick():
    plot_layout.children[2]=Paragraph(text="test")
    show(plot_layout)

plot_layout = layout([Laser_Dropdown,Section_Dropdown,p,button])

output_file("test.html")
show(plot_layout)

There are many mistakes in your code.. to much to mention them all. First try this: save the below script in a file script.py and open a cmd in the directory where you saved the file and run "bokeh serve script.py --show'

from bokeh.models.widgets import Button
from bokeh.io import curdoc

def onclick():
    print('somebody clicked the button and this can be read in the bokeh console')
button = Button(label='Update', button_type='primary')
button.on_click(onclick)

curdoc().add_root(button)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM