main.py 868 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import random
  2. import string
  3. from example_library import ExampleLibrary
  4. from taipy.gui import Gui
  5. # Initial value
  6. label = "Here is some text"
  7. page = """
  8. # Custom elements example
  9. ## Fraction:
  10. No denominator: <|123|example.fraction|>
  11. Denominator is 0: <|321|example.fraction|denominator=0|>
  12. Regular: <|355|example.fraction|denominator=113|>
  13. ## Custom label:
  14. Colored text: <|{label}|example.label|>
  15. <|Add a character|button|id=addChar|>
  16. <|Remove a character|button|id=removeChar|>
  17. """
  18. def on_action(state, id):
  19. if id == "addChar":
  20. # Add a random character to the end of 'label'
  21. state.label += random.choice(string.ascii_letters)
  22. elif id == "removeChar":
  23. # Remove the first character of 'label'
  24. if len(state.label) > 0:
  25. state.label = state.label[1:]
  26. Gui(page, libraries=[ExampleLibrary()]).run(debug=True)