02-button-callback

command
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Example 02: Button with Callback

Demonstrates interactive widgets with callback functions that update the UI in response to user actions.

What It Does

  • Creates a label and two buttons
  • Tracks button click count
  • Updates the label text when buttons are clicked
  • Shows how to use closures to maintain state

Running

cd examples/02-button-callback
go run main.go

Key Concepts

Callbacks

Buttons accept callback functions that execute when clicked:

let button = widget.NewButton("Click me!", () => {
    // This code runs when the button is clicked
    label.Text = "Updated text"
})
State Management

Variables in the script maintain state across callback executions:

let clickCount = 0

let button = widget.NewButton("Click me!", () => {
    clickCount = clickCount + 1  // Increments each time
})
Widget Property Updates

Widget properties can be modified after creation:

let label = widget.NewLabel("Initial text")
// Later in a callback:
label.Text = "New text"  // Updates the displayed text
Container Layouts

The VBox container arranges widgets vertically:

let layout = container.NewVBox(label, button1, button2)
Status and Result Callbacks

This example demonstrates using callbacks in the Go code to monitor execution:

statusCallback := func(status string) {
    fmt.Printf("Status: %s\n", status)
}

fyneWindow := fynerisor.NewWindow(w, nil, statusCallback, resultCallback)

Files

  • main.go: Go program with status monitoring
  • button.risor: Risor script with interactive buttons
  • README.md: This file

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL