Samples Hands-on code

# Code Examples

Klyn distributions include a `samples` directory with runnable examples. Use these programs to explore the standard library, the terminal GUI layer, database access, and larger application structure before starting your own project.

Where the Examples Live

From a source checkout, examples are available in the repository-level `samples` directory. Packaged Linux installations also install them under the Klyn home directory.

    cd samples
    klyn gui/Calculator.kn

When an example spans several files, launch its main file from the sample directory or use the path shown below. Klyn will resolve dependencies through its normal class-loading rules.

Available Examples

Examples are grouped with the same high-level categories and order as the tutorial sidebar. Each card tag shows the category it belongs to.

### Core Syntax

### MegaGame

Core Syntax

A larger sample entry point intended to exercise application-level composition and reusable language-level building blocks.

    klyn samples/MegaGame.kn

### Types and OOP

### POO

Types and OOP

A compact shape hierarchy showing classes, constructors, inheritance, overriding, and polymorphic calls in idiomatic Klyn.

    klyn samples/POO.kn

### File Handling

### Export XLSX

File Handling

Creates an XLSX workbook with a people directory, a second activity worksheet, and a line chart based on the exported monthly values.

    klyn samples/io/ExportXLSX.kn

### GUI

### Calculator

GUI

A compact graphical application showing event handling, widgets, and simple interaction patterns.

    klyn samples/gui/Calculator.kn

### Speed Demo Window

GUI

A custom speedometer widget built with `Canvas`, gradients, antialiased painting, sliders, and signal-property bindings.

    klyn samples/gui/SpeedDemoWindow.kn

### Clock Sample

GUI

An analog clock implemented as a custom `Canvas` widget. It combines gradients, antialiased painting, time-based geometry, and a GUI `Timer` that repaints once per second.

    klyn samples/gui/ClockSample.kn

### Slider Sample

GUI

Shows slider variants: filled track, ticks, values, vertical orientation, and live value tooltip during pointer drag.

    klyn samples/gui/SliderSample.kn

### DatePicker Sample

GUI

Shows the standard calendar popup and the `quickEditMode` workflow where the user selects a year, a month, then a day.

    klyn samples/gui/DatePickerSample.kn

### Menu Bar Sample

GUI

Demonstrates a desktop menu bar with File, Edit, and Help menus, mnemonic labels, shortcuts, icons, separators, and typed action events.

    klyn samples/gui/MenuBarSample.kn

### Terminal Widget

GUI

Embeds a `TerminalWidget` in a desktop window, demonstrates cwd tracking, multi-tab terminals, and the compact `singleTerminal` mode.

    klyn samples/gui/TerminalWidgetSample.kn

### Browser Widget

GUI

Embeds a styled HTML document with asynchronous navigation, retained rendering, history, and deterministic DOM scripting.

    klyn samples/gui/BrowserWidgetSample.kn

### Login Form

GUI

A MariaDB-backed login window using `FormLayout`, password input, default-button behavior, buddies, and prepared statements.

    klyn samples/gui/LoginForm.kn

### Color Chooser

GUI

Shows `Binding.twoWay` between sliders and spin boxes, plus `Binding.watch` to repaint a live color preview.

    klyn samples/gui/ColorChooser.kn

### Color Chooser 2

GUI

Refactors the color editor into reusable color lines that expose a bindable `value` signal property, while keeping the live preview synchronized.

    klyn samples/gui/ColorChooser2.kn

### Database Explorer

GUI

A larger GUI sample with a modal connection lightbox, split views, a schema tree, closable tabs, live database schema discovery, editable table models, read-only views, and an SQL editor with schema-aware completion.

    klyn samples/gui/dbexplorer/DatabaseExplorer.kn

### TUI

### Breakout

TUI

A multi-file terminal game. It is useful for understanding how a larger Klyn sample is split into several classes and views.

    klyn samples/Breakout/Breakout.kn

### Terminal Resize

TUI

Focuses on terminal resize behavior and is useful when validating layout and event-loop behavior on a new platform.

    klyn samples/TerminalResize.kn

### Advanced Topics

### Performance Benchmark

Advanced Topics

Runs equivalent Python, Klyn, and C++20 programs three times, compares cold and warm Klyn startup, and generates a self-contained HTML performance report.

    klyn samples/perf/Benchmark.kn

### SQL Login

Advanced Topics

A console MariaDB login flow using `DriverManager`, try-with-resources, and a prepared update statement.

    klyn samples/sql/Login.kn

### Entities and KQL

Advanced Topics

Builds a MariaDB article catalog with the Klyn Entity Framework, creates its schema, persists demonstration entities transactionally, and executes typed KQL price queries from a desktop GUI. A configured MariaDB database is required.

    klyn samples/sql/Entities.kn

### LLM

Advanced Topics

Exercises the language-level LLM helpers. This sample normally requires provider configuration and valid credentials. See the LLM API and Agents tutorial for the underlying request model.

    klyn samples/llm.kn

### Financial

Advanced Topics

Shows an LLM-backed financial agent sample and is a good place to inspect how domain logic can be combined with annotated tools and the agent loop described in the LLM API and Agents tutorial.

    klyn samples/Financial.kn

Next Step

Continue with Lexical Structure to understand the source rules used by these examples, or open API Reference while reading their imports.