builder.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. # -----------------------------------------------------------------------------------------
  12. # To execute this script, make sure that the taipy-gui package is installed in your
  13. # Python environment and run:
  14. # python <script>
  15. # -----------------------------------------------------------------------------------------
  16. import taipy.gui.builder as tgb
  17. from taipy.gui import Gui
  18. # Initially invested amount
  19. initial_investment = 100
  20. # Number of periods
  21. periods = 0
  22. # Number of periods
  23. final_amount = initial_investment
  24. # Interest rate by period
  25. rate = 5
  26. # Is the interest rate setting panel shown
  27. show_rate = False
  28. with tgb.Page() as rate_page:
  29. tgb.text("Rate (in %):")
  30. tgb.number("{rate}")
  31. with tgb.Page() as page:
  32. tgb.text("# Interest Calculator", mode="md")
  33. tgb.pane("{show_rate}", show_button=True, page="_rate_pane")
  34. tgb.text("Initial amount: ", inline=True)
  35. tgb.number("{initial_investment}")
  36. tgb.text("Periods", inline=True)
  37. tgb.number("{periods}", min=0, max=50)
  38. tgb.text("Final amount: ", inline=True)
  39. tgb.text("{final_amount}", format="%.2f", inline=True)
  40. # Invoked when any control value (initial_investment, rate, or periods) is changed.
  41. def on_change(state, var_name: str):
  42. # Cumulated interest percentage
  43. progress = pow(1 + state.rate / 100, state.periods)
  44. state.final_amount = state.initial_investment * progress
  45. if __name__ == "__main__":
  46. pages = {
  47. "main": page,
  48. "_rate_pane": rate_page,
  49. }
  50. Gui(pages=pages).run()