Message box (lv_msgbox)


The Message boxes act as pop-ups. They are built from a background container, a title, an optional close button, a text and optional buttons.

The text will be broken into multiple lines automatically and the height will be set automatically to include the text and the buttons.

The message box can be modal (blocking clicks on the rest of the screen) or not modal.

Parts and Styles

The message box is built from other widgets, so you can check these widgets' documentation for details.


Create a message box

lv_msgbox_create(parent, title, txt, btn_txts[], add_close_btn) creates a message box.

If parent is NULL the message box will be modal. title and txt are strings for the title and the text. btn_txts[] is an array with the buttons' text. E.g. const char * btn_txts[] = {"Ok", "Cancel", NULL}. add_close_btn can be true or false to add/don't add a close button.

Get the parts

The building blocks of the message box can be obtained using the following functions:

lv_obj_t * lv_msgbox_get_title(lv_obj_t * mbox);
lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * mbox);
lv_obj_t * lv_msgbox_get_text(lv_obj_t * mbox);
lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox);

Close the message box

lv_msgbox_close(msgbox) closes (deletes) the message box.


Learn more about Events.


Keys have effect on the close button and button matrix. You can add them manually to a group if required.

Learn more about Keys.


Simple Message box

#include "../../lv_examples.h"

static void event_cb(lv_event_t * e)
    lv_obj_t * obj = lv_event_get_target(e);
    LV_LOG_USER("Button %s clicked", lv_msgbox_get_active_button_text(obj));

void lv_example_msgbox_1(void)
    static const char * buttons[] = {"Apply", "Close", ""};

    lv_obj_t * mbox1 = lv_msgbox_create(NULL, "Hello", "This is a message box with two buttons.", buttons, true);
    lv_obj_add_event(mbox1, event_cb, LV_EVENT_VALUE_CHANGED, NULL);

def event_cb(e):
    mbox = e.get_target_obj()
    print("Button %s clicked" % mbox.get_active_button_text())

buttons = ["Apply", "Close", ""]

mbox1 = lv.msgbox(lv.scr_act(), "Hello", "This is a message box with two buttons.", buttons, True)
mbox1.add_event(event_cb, lv.EVENT.VALUE_CHANGED, None)