buttons1.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. """Add a square button with N possible internal states
  2. to a rendering window that calls an external function"""
  3. from vedo import Plotter, Mesh, dataurl, printc
  4. # Define a function that toggles the transparency of a mesh
  5. # and changes the button state
  6. def buttonfunc(obj, ename):
  7. mesh.alpha(1 - mesh.alpha()) # toggle mesh transparency
  8. bu.switch() # change to next status
  9. printc(bu.status(), box="_", dim=True)
  10. # Load a mesh and set its color to violet
  11. mesh = Mesh(dataurl+"magnolia.vtk").c("violet").flat()
  12. # Create an instance of the Plotter class with axes style-11 enabled
  13. plt = Plotter(axes=11)
  14. # Add a button to the plotter with buttonfunc as the callback function
  15. bu = plt.add_button(
  16. buttonfunc,
  17. pos=(0.7, 0.1), # x,y fraction from bottom left corner
  18. states=["click to hide", "click to show"], # text for each state
  19. c=["w", "w"], # font color for each state
  20. bc=["dg", "dv"], # background color for each state
  21. font="courier", # font type
  22. size=30, # font size
  23. bold=True, # bold font
  24. italic=False, # non-italic font style
  25. )
  26. # Show the mesh, docstring, and button in the plot
  27. plt.show(mesh, __doc__).close()