tutorial.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """Welcome to Pynecone! This file outlines the steps to create a basic app."""
  2. # Import pynecone.
  3. import pcconfig
  4. import pynecone as pc
  5. docs_url = "https://pynecone.io/docs/getting-started/introduction"
  6. title = "Welcome to Pynecone!"
  7. filename = f"{pcconfig.APP_NAME}/{pcconfig.APP_NAME}.py"
  8. class State(pc.State):
  9. """The app state."""
  10. # The colors to cycle through.
  11. colors = ["black", "red", "orange", "yellow", "green", "blue", "purple"]
  12. # The index of the current color.
  13. index = 0
  14. def next_color(self):
  15. """Cycle to the next color."""
  16. self.index = (self.index + 1) % len(self.colors)
  17. @pc.var
  18. def color(self):
  19. return self.colors[self.index]
  20. # Define views.
  21. def welcome_text():
  22. return pc.heading(
  23. title,
  24. font_size="2.5em",
  25. on_click=State.next_color,
  26. color=State.color,
  27. _hover={"cursor": "pointer"},
  28. )
  29. def instructions():
  30. return pc.box(
  31. "Get started by editing ",
  32. pc.code(
  33. filename,
  34. font_size="0.8em",
  35. ),
  36. )
  37. def doclink():
  38. return pc.link(
  39. "Check out our docs!",
  40. href=docs_url,
  41. border="0.1em solid",
  42. padding="0.5em",
  43. _hover={
  44. "border_color": State.color,
  45. "color": State.color,
  46. },
  47. )
  48. def index():
  49. return pc.container(
  50. pc.vstack(
  51. welcome_text(),
  52. instructions(),
  53. doclink(),
  54. spacing="2em",
  55. ),
  56. padding_y="5em",
  57. font_size="2em",
  58. text_align="center",
  59. height="100vh",
  60. )
  61. # Add state and page to the app.
  62. app = pc.App(state=State)
  63. app.add_page(index, title=title)
  64. app.compile()