Ir al contenido

Alerta

Un mensaje con un solo botón de Aceptar. kind ("info", "success", "warning", "error") añade un icono.

ui.alert · Categoría: Diálogos · Referencia completa →

AlertaAlerta
  • Para avisar de algo que hay que confirmar (una exportación terminó, un archivo no se pudo abrir).
from pyzed import ui
ui.dialog_layer(main_view(), ui.alert("The export finished: 128 files were written.", on_close,
title="Export", kind="success", width=360))
Alerta: kind=NoneAlerta: kind=None
kind=None
Código
ui.alert("The file was moved to the trash.", on_close, width=320)
Alerta: kind="info"Alerta: kind="info"
kind="info"
Código
ui.alert("A new version is available.", on_close, kind="info", width=320)
Alerta: kind="success"Alerta: kind="success"
kind="success"
Código
ui.alert("128 files were exported.", on_close, kind="success", title="Export", width=320)
Alerta: kind="warning"Alerta: kind="warning"
kind="warning"
Código
ui.alert("The disk is almost full.", on_close, kind="warning", width=320)
Alerta: kind="error"Alerta: kind="error"
kind="error"
Código
ui.alert("notes.py could not be opened.", on_close, kind="error", title="Error", width=320)
Alerta: ok_label="Got it"Alerta: ok_label="Got it"
ok_label="Got it"
Código
ui.alert("Shortcuts changed in this version.", on_close, ok_label="Got it", width=320)

Alerta tiene 1 evento propios, en la tabla de abajo. Como todo widget, también tiene los 18 eventos comunes (click, double_click, right_click, mouse_enter, drag, key_down, resize…), que se conectan con .on(...): mira Eventos y Eventos de cada componente.

Evento El handler recibe Cuándo
on_close () El botón y el icono de cerrar.

El handler recibe es lo que Pyzed le pasa a tu función: () es nada. Cualquier handler también puede ser un mensaje (un valor que no se puede llamar), que va a update().

Los mismos eventos escritos de tres formas. Imperativa: métodos de la app que cambian self. Declarativa: los handlers producen mensajes y un único update() decide. Funcional: una función pura dibuja un estado inmutable y pide cambios con set_state(...). Mira Imperativo, declarativo y funcional.

class Export(pz.App):
def __init__(self):
self.done = True
def view(self):
alert = ui.alert("128 files were written.", lambda: setattr(self, "done", False), # on_close
title="Export", kind="success")
return ui.dialog_layer(main_view(), alert if self.done else None)
alert(message, on_close, *, title=None, kind=None, ok_label=None, width=400, theme=None)

Un mensaje con un botón.

Propiedad Por defecto Descripción
message obligatorio Texto o widget.
title None Título.
kind None "info", "success", "warning" o "error" añade un icono.
ok_label None Texto del botón (por defecto: Aceptar, traducido).
width 400 Ancho: píxeles, "fill", "shrink" o "fill:N" (proporción).
theme None Tema a usar en lugar del actual (pyzed.theme.current()).

Eventos: on_close (eventos).

Referencia completa →