.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/multiple_fonts.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_feature_demo_multiple_fonts.py: Multiple Fonts ============== Example demonstrating the capabilities of text to be rendered in multiple different fonts. .. GENERATED FROM PYTHON SOURCE LINES 8-60 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_multiple_fonts_001.webp :alt: multiple fonts :srcset: /_gallery/feature_demo/images/sphx_glr_multiple_fonts_001.webp :class: sphx-glr-single-img .. code-block:: Python from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx from datetime import datetime now = datetime.now() text = now.strftime("%H:%M:%S") material = gfx.TextMaterial( color="#B4F8C8", outline_color="#000", outline_thickness=0.15 ) text_noto = gfx.Text( text="Noto Sans: " + text, # family="Noto Sans", material=material, ) text_noto.local.position = (0, -40, 0) text_humor = gfx.Text( text="Humor Sans: " + text, family="Humor Sans", material=material, ) text_humor.local.position = (0, 0, 0) text_instructions = gfx.Text( text="Click to update the clock", material=material, ) text_instructions.local.position = (0, 40, 0) scene = gfx.Scene() scene.add(text_noto, text_humor, text_instructions) camera = gfx.OrthographicCamera(400, 300) renderer = gfx.renderers.WgpuRenderer(RenderCanvas(size=(800, 600))) @renderer.add_event_handler("pointer_down") def change_text(event): now = datetime.now() text = now.strftime("%H:%M:%S") text_noto.set_text("Noto Sans: " + text) text_humor.set_text("Humor Sans: " + text) renderer.request_draw() renderer.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.275 seconds) .. _sphx_glr_download__gallery_feature_demo_multiple_fonts.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: multiple_fonts.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: multiple_fonts.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: multiple_fonts.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html