Skip to content

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 →

MarkdownMarkdown
  • 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)
Markdown: Headings and emphasisMarkdown: Headings and emphasis
Headings and emphasis
Code
ui.markdown("## Title\nSome **bold** and *italic* text.", width=320)
Markdown: ListsMarkdown: Lists
Lists
Code
ui.markdown("- Fast\n- Native\n- Pythonic\n\n1. Install\n2. Run", width=320)
Markdown: CodeMarkdown: Code
Code
Code
ui.markdown("Run `pyzed new`:\n\n```python\nimport pyzed as pz\n```", width=320)
Markdown: Quote and linkMarkdown: Quote and link
Quote and link
Code
ui.markdown("> Desktop UIs in Python.\n\nSee [the docs](https://albakore.github.io/pyzed/).", width=320, on_link=on_link)
Markdown: TableMarkdown: Table
Table
Code
ui.markdown("| Key | Action |\n| --- | --- |\n| ctrl-s | Save |\n| ctrl-p | Open |", width=320)

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().

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)
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).

Full reference →

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).

Full reference →