Markdown
Renders Markdown (headings, lists, code blocks, quotes, tables, links) with the theme’s text, link and code colors. on_link(url) receives clicked links. pz.markdown is the base widget with explicit colors.
ui.markdown · Category: Code and tools · Full reference →


ui.markdown('''## Release notes
Pyzed **0.4** adds the *component designer*, `pyzed build` and [styles](https://iced.rs).
- Track grids and flex- Ready-made dialogs''', width=460, on_link=on_link)When to use
Section titled “When to use”- For READMEs, release notes, help pages and chat messages.
from pyzed import ui
ui.markdown('''## Release notes
Pyzed **0.4** adds the *component designer*, `pyzed build` and [styles](https://iced.rs).
- Track grids and flex- Ready-made dialogs''', width=460, on_link=on_link)Variants
Section titled “Variants”Elements
Section titled “Elements”

Code
ui.markdown("## Title\nSome **bold** and *italic* text.", width=320)

Code
ui.markdown("- Fast\n- Native\n- Pythonic\n\n1. Install\n2. Run", width=320)

Code
ui.markdown("Run `pyzed new`:\n\n```python\nimport pyzed as pz\n```", width=320)

Code
ui.markdown("> Desktop UIs in Python.\n\nSee [the docs](https://albakore.github.io/pyzed/).", width=320, on_link=on_link)

Code
ui.markdown("| Key | Action |\n| --- | --- |\n| ctrl-s | Save |\n| ctrl-p | Open |", width=320)Events
Section titled “Events”Markdown has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Of | Handler gets | When |
|---|---|---|---|
on_link |
ui.markdown, pz.markdown |
(url) |
Callable that receives the URL when a link is clicked. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
import webbrowser
class Notes(pz.App): def __init__(self): self.last = None
def follow(self, url): # on_link: the URL of the clicked link self.last = url webbrowser.open(url)
def view(self): return ui.markdown("Read the [docs](https://albakore.github.io/pyzed/) or the " "[changelog](https://github.com/albakore/pyzed).", on_link=self.follow)from dataclasses import dataclass
@dataclassclass Link: url: str
class Notes(pz.App): def update(self, message): match message: case Link(url) if url.startswith("app:"): print("internal page", url[4:]) # links can drive the app, too case Link(url): print("open", url)
def view(self): return ui.markdown("Go to [settings](app:settings) or the [docs](https://albakore.github.io/pyzed/).", on_link=Link)from dataclasses import dataclass
@dataclass(frozen=True)class State: page: str = "home"
PAGES = {"home": "Welcome. See [about](about).", "about": "Made with Pyzed. Back [home](home)."}
def view(state, set_state): text = PAGES.get(state.page, "Not found. Back [home](home).") return ui.markdown(text, on_link=lambda url: set_state(page=url))Properties and API
Section titled “Properties and API”ui.markdown
Section titled “ui.markdown”markdown(source, *, size=None, on_link=None, width=None, selectable=None, theme=None)pz.markdown with the theme’s text, link and code colors.
| Property | Default | Description |
|---|---|---|
source |
required | The Markdown text. |
size |
None |
Size. |
width |
None |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
selectable |
None |
Same as in pz.markdown; the selection uses the theme’s selection color. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_link (events).
pz.markdown
Section titled “pz.markdown”markdown( source, *, size=14.0, color=None, link_color=None, code_color=None, code_bg=None, on_link=None, width=None, selectable=None, selection_color=None,)Renders Markdown (headings, lists, code blocks, quotes, tables, links…). For the theme colors use ui.markdown.
| Property | Default | Description |
|---|---|---|
source |
required | The Markdown text. |
size |
14.0 |
Size. |
color |
None |
Text or icon color. |
link_color |
None |
Link color. |
code_color |
None |
Code color. |
code_bg |
None |
Code background. |
width |
None |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
selectable |
None |
True lets the mouse select the text (drag, double-click a word, triple-click a block) and Ctrl+C copy it. A string names a selection group: the texts and Markdown of one group form a single selection, in the order they are drawn (the lines of a log, the messages of a chat). |
selection_color |
None |
Color behind the selected text. |
Events: on_link (events).