> For the complete documentation index, see [llms.txt](https://luadoc.edgetx.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://luadoc.edgetx.org/2.11/lua-api-reference/lvgl-for-lua/examples.md).

# Examples

Some simple example scripts to set the stage.

### One-Time script

```lua
local exitTool = false

local function close()
  lvgl.confirm({title="Exit", message="Really exit?",
    confirm=(function() exitTool = true end)
  })
end

local function init()
  if lvgl == nil then return end

  lvgl.clear();

  local pg = lvgl.page({title="Test Tool", subtitle="Page 1", back=close})

  pg:label({x=70, y=16, color=BLACK, font=DBLSIZE, text="Test Page"})
  pg:button({x=200, y=150, text="CLOSE", press=close})
end

local function run(event, touchState)
  if lvgl == nil then
    lcd.drawText(0, 0, "LVGL support required", COLOR_THEME_WARNING)
  end

  if (exitTool) then return 2 end
  return 0
end

return {init = init, run = run, useLvgl=true}
```

When run this produces the page shown below.

![](https://1758057436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLy8RKETivxoHMb7Zzqkb%2Fuploads%2FUZJEwDlzEuJ9SvXBj1CV%2Fscreenshot_tx16s_24-08-08_19-41-54.png?alt=media\&token=a06bbca3-355c-4fe2-8f70-28369a869d45)

The user can exit the script by tapping the 'CLOSE' button or tapping the 'EdgeTX' button in the top-left corner. In both cases a popup dialog will be shown - if the user selects 'Yes' the script will close.

![](https://1758057436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLy8RKETivxoHMb7Zzqkb%2Fuploads%2FZ11rbuGSs6rbJ8U5e9Cp%2Fscreenshot_tx16s_24-08-08_19-42-01.png?alt=media\&token=3d1f4211-9363-4f91-80ce-9f810fb85358)

### Widget script

LVGL version of the 'Counter' script.

```lua
local options = {
  { "Color", COLOR, COLOR_THEME_SECONDARY1 },
  { "Shadow", BOOL, 0 }
}

local function create(zone, options)
  local wgt = { zone=zone, options=options, counter=0 }
  return wgt
end

local function update(wgt, options)
  wgt.options = options

  lvgl.clear()

  if wgt.options.Shadow ~= 0 then
    lvgl.label({x=wgt.zone.x+1, y=wgt.zone.y+1, color=BLACK, font=DBLSIZE, text=(function() return wgt.counter end)})
  end
  lvgl.label({x=wgt.zone.x, y=wgt.zone.y, color=wgt.options.Color, font=DBLSIZE, text=(function() return wgt.counter end)})
end

local function background(wgt)
  wgt.counter = wgt.counter + 1
end

function refresh(wgt)
  wgt.counter = wgt.counter + 1
end

return { name="CounterLVGL", options=options, create=create, update=update, refresh=refresh, background=background, useLvgl=true }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://luadoc.edgetx.org/2.11/lua-api-reference/lvgl-for-lua/examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
