GUIDE / START

Your first app

Create a project, understand its files, write a counter, run it, and change it while it runs.

Core janelkit Included with janelkit. Nothing extra to install.
CHAPTER 03 / 29~4 min read · try examples at your own pace
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

What you will learn

  • How to create and run a project with janel new and python main.py.
  • What each file in a new project is for.
  • How main.py starts the application.
  • How to write, run and check a complete component.
  • How janel dev reloads your changes while you work.

1. Create a project

Run these commands in a terminal, with your virtual environment active. janel new creates a folder with a working starter application. cd moves into it. python main.py runs the application.

The starter is a small demo: a greeting that uses what you type, a click counter and a theme button. Its texts are in Spanish; that is only the sample content.

shell
janel new first-counter
cd first-counter
python main.py
Copy

What you should see

A window opens with a greeting, a text field, a Clicks counter and a button to switch between light and dark theme. Close it before continuing.

Common mistakes

  • janel new refuses to write into a folder that already has files. Choose a new name instead of deleting an existing project.
  • Run python main.py from the project folder, the one that contains main.py, not from src.

2. Know what each file is for

Open the folder in your editor. You will spend almost all your time in src. Its folder is added to Python’s import path, so a component can import from services or components by name.

PathWhat it is for
main.pyStarts the application. You rarely change it.
src/App.janelThe root component: the main window of your application.
src/components/Smaller reusable components. The starter has Counter.janel.
src/pages/Screens, such as the pages of a janelkit-router stack. Empty at first.
src/services/Ordinary Python modules without interface, such as users.py. Business logic belongs here.
assets/Images and other files your application uses.
pyproject.toml, README.md, .gitignoreProject metadata, notes and version-control settings.

3. How main.py starts everything

A desktop program needs a starting point, just like a script. main.py calls run with the path of the root component. run compiles it, opens its window and then waits for clicks and key presses until the user closes the window. It returns an exit code, which SystemExit hands back to the operating system.

main.py
from pathlib import Path

from janelkit import run

if __name__ == "__main__":
    raise SystemExit(run(Path(__file__).parent / "src" / "App.janel"))
Copy

Complete file · Save as main.py.

How it works

  1. Path(__file__).parent is the folder that contains main.py, so the path works no matter which folder the terminal is in.
  2. The __main__ guard runs the application only when this file is executed directly.
  3. run keeps the process alive while the window is open. You never write your own loop to keep a window on screen.

4. Replace App.janel with a counter

Replace the whole content of src/App.janel with the component below. Replacing only part of it can leave two scripts or two roots, which is an error. The starter files in components and services can stay; this counter does not import them.

The counter has two buttons. Reset is disabled while the count is zero; that rule is written once, as an expression, instead of being updated by hand.

janel
<script lang="python">
from janelkit import state

count = state(0)

def increment():
    count.value += 1

def reset():
    count.value = 0
</script>

<window title="My first counter" width={420} height={260}>
  <column class="page">
    <text>You clicked {count} times.</text>
    <row class="actions">
      <button variant="primary" on:click={increment}>Increment</button>
      <button on:click={reset} enabled={count > 0}>Reset</button>
    </row>
  </column>
</window>

<style>
.page { padding: 24px; gap: 16px; }
.actions { gap: 8px; }
</style>
Copy

Complete component · Save as src/App.janel in a scaffolded project.

How it works

  1. count = state(0) creates the number once, when the window is created.
  2. increment and reset are ordinary Python functions. Inside Python you read and write the number through count.value.
  3. In the template you write count, not count.value: JanelKit reads the value for you.
  4. on:click={increment} connects the button to the function. Defining a function does not run it; the click does.
  5. enabled={count > 0} is recalculated whenever count changes, so Reset turns on and off by itself.
  6. <row> places the two buttons side by side; <column> stacks the sentence above them.

Learn moreReactive state ↗Events ↗

5. Run it and check every behavior

Run the application again from the project folder. Do not stop at "a window appeared": click each button and check the result. That is how you know the event connections and the data both work.

  1. Check the title is My first counter, the sentence says 0 and Reset is disabled.
  2. Click Increment twice. The sentence changes after each click and Reset becomes enabled.
  3. Click Reset. The sentence returns to 0 and Reset is disabled again.
  4. Close and reopen the application. It starts at 0: ordinary state lives in memory, not on disk.
shell
python main.py
Copy

What you should see

You clicked 0 times. at first; You clicked 2 times. after two clicks; back to 0 after Reset, with Reset disabled.

6. Work faster with janel dev

janel dev runs the application and watches your files. Saving a .janel file reloads its view in place; a component whose script did not change keeps its state, so you can adjust the layout without clicking back to where you were. Saving a .py file restarts the application. If an edit has an error, the error is printed and the last working view stays open.

  1. Start janel dev, click Increment a few times, then change the window title and save. The title changes; the count is kept.
  2. Change increment to add 2 and save. The script changed, so the component restarts from 0 with the new rule.
shell
janel dev
Copy

Common mistakes

  • Keeping state during a reload is a development convenience, not saving. To test initial values, restart the application.

Learn moreCLI and tooling ↗

7. Practice: add a Decrement button

Add a Decrement button that never takes the count below zero. Write the rule in a new function in the existing script and add one more <button> inside the <row>. Do not add a second script or a second <window>.

If something fails, read the terminal: errors give the file, line and column, and often suggest the name you meant. Compilation catches structural mistakes such as a misspelled element; an error inside a function only appears when that function runs.

Common mistakes

  • In Python functions write count.value; in the template write count.
  • A function that is never connected with on:click never runs.
  • If an edit seems ignored, check that you saved the file in the project you are actually running.

Key points

  • janel new creates a project; python main.py runs it; janel dev reloads it as you work.
  • Your code lives in src: App.janel is the main window, components and services hold the rest.
  • Test behavior, not just startup: click everything and check what changes.

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.