Tutorial: Hello, World
Build and run your first ScriptWeaver app in about a minute.
Your first window
ScriptWeaver gives you a main window for free — it's the global app. Drop a
button into it:
const btn = app.TButton({
text: 'Hello, World!',
onClick: () => sw.dialog.alert('You clicked it!'),
});
btn.pack.configure({ padx: 40, pady: 40 });
Save that as hello.js and run it:
scriptweaver hello.js
A window opens with a single button; clicking it pops up a native dialog. That's a complete, native, cross-platform app — no HTML, no browser engine.
Adding some state
Most apps remember something. Here's a click counter — a label that updates on every press:
let count = 0;
const label = app.TLabel({ text: 'Clicks: 0' });
label.pack.configure({ padx: 40, pady: 8 });
const btn = app.TButton({
text: 'Click me',
onClick: () => {
count += 1;
label.text = `Clicks: ${count}`; // an option is also a live property
},
});
btn.pack.configure({ pady: 8 });
app.wm.title('Counter');
Run it the same way. Each click bumps the counter and the label updates instantly.
What just happened
appis the pre-created main window. Because it's a container,app.TButton({…})andapp.TLabel({…})create those widgets inside it.onClickruns your JavaScript when the button is activated.- Options are live properties. Setting
label.text = …updates the widget immediately — there's no separate redraw step. widget.pack.configure({…})places a widget.packstacks widgets top-to-bottom by default;padx/padyadd breathing room.app.wm.title(…)sets the window title.
Next steps
- Widget basics — the model shared by every widget
- Layout — arranging widgets beyond a simple stack
- Events & binding — keyboard, mouse, and more
- Widget reference — every available widget