buttons3.py 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Create a button using an Image icon to show its state"""
  2. from vedo import Cone, Image, dataurl, ButtonWidget, Plotter
  3. def button_func(widget, evtname):
  4. print("button_func called")
  5. cone.color(button.state)
  6. if button.state:
  7. plt.background("black")
  8. else:
  9. plt.background("white")
  10. def on_mouse_click(event):
  11. if event.object:
  12. print("on_mouse_click", event)
  13. cone.color(button.state)
  14. # Create a cone
  15. cone = Cone().color(0)
  16. # Create a plotter
  17. plt = Plotter(bg='w', axes=1)
  18. plt.add_callback('mouse click', on_mouse_click)
  19. plt.add(cone, __doc__)
  20. # Create a button widget
  21. img0 = Image(dataurl+"images/play-button.png")
  22. img1 = Image(dataurl+"images/power-on.png")
  23. button = ButtonWidget(
  24. button_func,
  25. # states=["State 0", "State 1"],
  26. states=[img0, img1],
  27. c=["red4", "blue4"],
  28. bc=("k9", "k5"),
  29. size=100,
  30. plotter=plt,
  31. )
  32. button.pos([0,0]).enable()
  33. plt.show(elevation=-40)