Debian Codegraph @

docs/widgets/builtins.md

raw symbols SCIP
1 We provide a growing selection of widgets you can drop straight into your projects. Looking at the `widgets` submodule's contents can help illuminate you on the exact selection, but this page describes the most commonly used ones.
2
3 ## A note about `auto`
4
5 Some widgets below will have an `Auto syntax` field shown. The format shown can be used by the [auto](/reference/pytermgui/widgets/__init__#pytermgui.widgets.__init__.auto) function to generate widgets from Python datatypes. This function is conveniently called within `Container` and all its subclasses (`Splitter`, `Window`, `Collapsible` & more) to let you easily create widgets with minimal imports.
6
7 For example:
8
9 ```python
10 from pytermgui import Container
11
12 container = Container(
13 "[bold accent]This is my example",
14 "",
15 "[surface+1 dim italic]It is very cool, you see",
16 "",
17 {"My first label": ["Some button"]},
18 {"My second label": [False]},
19 "",
20 ("Left side", "Middle", "Right side"),
21 "",
22 ["Submit button"]
23 )
24 ```
25
26 ...is functionally identical to:
27
28 ```python
29 from pytermgui import Container, Label, Splitter, Button, Checkbox
30
31 container = Container(
32 Label("[bold accent]This is my example"),
33 Label(""),
34 Label("[surface+1 dim italic]It is very cool, you see"),
35 Label(""),
36 Splitter(
37 Label("My first label", parent_align=0),
38 Button("Some button", parent_align=2),
39 ),
40 Splitter(
41 Label("My second label"),
42 Checkbox(),
43 ),
44 Label(""),
45 Splitter(Label("Left side"), Label("Middle"), Label("Right side")),
46 Label(""),
47 Button("Submit button"),
48 )
49 ```
50
51 You can use whichever you find more convenient and readable.
52
53 ---
54
55 ## [Label](/reference/pytermgui/widgets/base/#pytermgui.widgets.base.Label)
56
57 A simple widget meant to display text. Supports line breaking and styling using both markup and simple callables.
58
59 **Auto syntax**: `"label_value"`
60
61 **Chars**: N/A
62
63 **Styles**:
64
65 - `value`: Applies to the text within the label.
66
67 Default: No styling.
68
69 ---
70
71 ## [Container](/reference/pytermgui/widgets/containers#pytermgui.widgets.containers.Container)
72
73 A widget to display other widgets, stacked vertically. It may display a box around said widgets as well, using the `border` and `corner` characters.
74
75 **Auto syntax**: N/A
76
77 **Chars**:
78
79 - `border`: A `list[str]` in the order `left, top, right, bottom` that makes up the borders of the outer box.
80 - `corner`: A `list[str]` in the order `top_left, top_right, bottom_right, bottom_left` that makes up the corners of the outer box.
81
82 **Styles**:
83
84 - `border`: Applies to all border characters of the outer box.
85
86 Default: `surface`.
87
88 - `corner`: Applies to all corner characters of the outer box.
89
90 Default: `surface`.
91
92 - `fill`: Applies to the filler characters used for padding.
93
94 Default: `background`.
95
96 ---
97
98 ## [Splitter](/reference/pytermgui/widgets/containers#pytermgui.widgets.containers.Splitter)
99
100
101 Similar to Container, but displays widgets stacked horizontally instead. Each widget is separated by the `separator` character set.
102
103 **Auto syntax**:
104
105 - `(widget1, widget2, ...)`
106 - `{widget_aligned_left: widget_aligned_right}`
107
108 **Chars**:
109
110 - `separator`: The `str` used to join the contained widgets.
111
112 **Styles**:
113
114 - `separator`: Applies to the `separator` character.
115
116 Default: `surface`.
117
118 ---
119
120 ## [Collapsible](/reference/pytermgui/widgets/collapsible#pytermgui.widgets.collapsible)
121
122 A widget that hides or shows whatever other widgets it is given. It will always display its "trigger", the `Button` used to collapse or expand its content.
123
124 **Auto syntax**: N/A
125
126 **Chars**:
127
128 - See `Container`.
129
130 **Styles**:
131
132 - See `Container`.
133
134 ---
135
136 ## [Window](/reference/pytermgui/window_manager/window#pytermgui.window_manager.window)
137
138 An extended version of `Container`, used in the `window_manager` context.
139
140 **Auto syntax**: N/A
141
142 **Chars**:
143
144 See `Container`.
145
146 **Styles**:
147
148 Same as `Container`, but expanded with:
149
150 - `border_focused`: Analogous to `border`, but only applied when the window is focused.
151
152 Default: `surface`.
153
154 - `corner_focused`: Analogous to `corner`, but only applied when the window is focused.
155
156 Default: `surface`.
157
158 - `border_blurred`: Analogous to `border`, but only applied when the window is **NOT** focused.
159
160 Default: `surface-2`.
161
162 - `corner_blurred`: Analogous to `corner`, but only applied when the window is **NOT** focused.
163
164 Default: `surface-2`.
165
166 ---
167
168 ## [Button](/reference/pytermgui/widgets/button#pytermgui.widgets.button)
169
170
171 Something clickable. All widgets can be made clickable by defining an `on_click` method, but this widget looks the part as well.
172
173 **Auto syntax**:
174
175 - `["button_label", button_callback]`
176
177 **Chars**:
178
179 - `delimiter`: a `list[str]` in the order `left, right`. Each character will be placed at the respective sides of the label.
180
181 **Styles**:
182
183 > All styles here apply to the full label, including the left and right hand side delimiters.
184
185 - `label`: Applies in the normal state (e.g. no hover, click applied).
186
187 Default: `@surface dim`.
188
189 - `highlight`: Applies when the button is interacted with.
190
191 Default: `@surface+1 dim`.
192
193
194 ---
195
196 ## [KeyboardButton](/reference/pytermgui/widgets/keyboard_button#pytermgui.widgets.keyboard_button)
197
198
199
200 Much like button, but has a default binding applied to it. This binding is also reflected in its label.
201
202 **Auto syntax**: N/A
203
204 **Chars**:
205
206 - All `Button` chars
207 - `bracket`: Used to wrap the button's bound key.
208
209 **Styles**:
210
211 - See `Button`.
212
213
214 ---
215
216
217 ## [Checkbox](/reference/pytermgui/widgets/checkbox#pytermgui.widgets.checkbox)
218
219 A simple check box, you know the drill.
220
221 **Auto syntax**:
222
223 - `[bool_default, callback_method]`
224
225 **Chars**:
226
227 - `delimiter`: Wraps the checkbox's value
228 - `checked`: The character inserted between delimiters when the widget is checked.
229 - `unchecked`: The character inserted between delimiters when the widget is **un**checked.
230
231
232 **Styles**:
233
234 - See `Button`.
235
236
237 ---
238
239 ## [Toggle](/reference/pytermgui/widgets/toggle#pytermgui.widgets.toggle)
240
241 A button that toggles its label between the two given values.
242
243 **Auto syntax**:
244
245 - `[("label_1", "label_2"), callback_method]`
246
247 **Chars**:
248
249 - See `Button`.
250
251 **Styles**:
252
253 - See `Button`.
254
255 ---
256
257 ## [Slider](/reference/pytermgui/widgets/slider#pytermgui.widgets.slider.Slider)
258
259 A widget to display and/or control a floating point value.
260
261 **Auto syntax**: N/A
262
263 **Chars**:
264
265 - `cursor`: The character placed at the end of the filled section. If nothing is given, `rail` is used.
266 - `rail`: Used to fill up the width of the slider, colored as applicable.
267 - `delimiter`: Wraps the `rail` characters on both sides.
268
269 **Styles**:
270
271 - `cursor`: Applied to the `cursor` character, or the last character of the rail.
272
273 Default: `primary`.
274
275 - `filled`: Applied to the filled section of the rail if the slider is **not** selected.
276
277 Default: `surface+1`.
278
279 - `filled_selected`: Applied to the filled section of the rail if the slider is selected.
280
281 Default: `primary`.
282
283 - `unfilled`: Applied to the unfilled section of the rail if the slider is **not** selected.
284
285 Default: `surface-1`.
286
287 - `unfilled_selected`: Applied to the unfilled section of the rail if the slider is selected.
288
289 Default: `surface`.
290
291 ---
292
293 ## [InputField](/reference/pytermgui/widgets/input_field#pytermgui.widgets.input_field.InputField)
294
295 A field to display input. Should be used in a context that sends it keyboard inputs, such as `WindowManager`.
296
297 **Auto syntax**: N/A
298
299 **Chars**: N/A
300
301 **Styles**:
302
303 - `value`: Applies to the text of the input field.
304
305 Default: No styling.
306
307 - `prompt`: Applies to the string displayed before the field's value, controlled by the `prompt` parameter.
308
309 Default: `surface+2`
310
311 - `cursor`: Applies to the field's cursor.
312
313 Default: `@primary dim #auto`
314
315 ---
316
317 ## [PixelMatrix](/reference/pytermgui/widgets/pixel_matrix#pytermgui.widgets.pixel_matrix.PixelMatrix)
318
319 A customizable matrix of unicode pixels. With some image decoding, it can be used to display low-resolution pictures.
320
321 **Auto syntax**: N/A
322
323 **Chars**: N/A
324
325 **Styles**: N/A
326
327 ---
328
329 ## [DensePixelMatrix](/reference/pytermgui/widgets/pixel_matrix/#pytermgui.widgets.pixel_matrix.DensePixelMatrix)
330
331 Similar to `PixelMatrix`, but instead of using two unicode block characters per pixel, it uses either the upper or lower half of one. Allows for higher resolution pictures!
332
333 **Auto syntax**: N/A
334
335 **Chars**: See `PixelMatrix`
336
337 **Styles**: See `PixelMatrix`
338
339
340