UI functions
- pyegui.add_enabled(enabled, update_fun)
Add a section that is possibly disabled, i.e. greyed out and non-interactive.
If you call add_enabled from within an already disabled Ui, the result will always be disabled, even if the enabled argument is true.
Example:
add_enabled(False, lambda: button_clicked("you can't click me")) button_clicked("but you can click me")
- pyegui.add_space(amount)
Add extra space before the next widget.
The direction is dependent on the layout. Example:
add_space(5) heading("I'm so spaced now")
- pyegui.button_clicked(text)
Returns true if the button was clicked this frame
Example:
if button_clicked("click me"): print("click me, my friend")
- pyegui.centered_and_justified(update_fun)
This will make the next added widget centered and justified in the available space.
Only one widget may be added inside update_func!
- pyegui.checkbox(checked, text)
Show a checkbox.
Example:
data = Bool(false) # inside update_func checkbox(data, "check me")
- pyegui.code(text)
Show text as monospace with a gray background.
Example:
code("print(42 + 27)")
- pyegui.code_editor(text)
Show singleline text field and update the text
Example:
text = Str("print(42 + 27)") # inside update func code_editor(text)
- pyegui.collapsing(heading, update_fun)
A CollapsingHeader that starts out collapsed.
Example:
def update_func(): heading("hi") collapsing("collapsed", update_func)
- pyegui.color_edit_button_rgb(rgb)
Shows a button with the given color. If the user clicks the button, a full color picker is shown.
Example:
color = RGB(69, 69, 69) # inside udpate_func color_edit_button_rgb(color) heading(f"r:{color.r} g:{color.g} b:{color.b}")
- pyegui.combo_box(current_value, alternatives, names, label)
Shows a combo box with values defined in “alternatives” and their corresponding names defined in “names”
Example:
RED = 0 GREEN = 1 BLUE = 2 data = Int(RED) def update_func(a): combo_box(data, [RED, GREEN, BLUE], ["red", "green", "blue"], "choose your fate")
- pyegui.date_picker_button(selection)
Shows a date, and will open a date picker popup when clicked.
Example:
date = Date(datetime.datetime.now()) # inside update_func date_picker_button(date)
- pyegui.disable()
Calling disable() will cause the Ui to deny all future interaction and all the widgets will draw with a gray look.
Usually it is more convenient to use add_enabled.
Note that once disabled, there is no way to re-enable the Ui.
Example:
disable() if button_clicked("you can't click me"): pass
- pyegui.drag_float(value, min, max, speed)
Control float by dragging the number.
Example:
data = Float(5) # inside update_func drag_float(data, 0, 50, 1.5)
- pyegui.drag_int(value, min, max, speed)
Control int by dragging the number.
Example:
data = Int(5) # inside update_func drag_int(data, 0, 50, 1)
- pyegui.group(update_fun)
Visually groups the contents together.
Example:
def update_func(): heading("hi") heading("there") group(update_func)
- pyegui.heading(text)
Show large text
Example:
heading("hello")
- pyegui.horizontal(update_fun)
Start a ui with horizontal layout. After you have called this, the function registers the contents as any other widget.
Elements will be centered on the Y axis, i.e. adjusted up and down to lie in the center of the horizontal layout. The initial height is style.spacing.interact_size.y. Centering is almost always what you want if you are planning to mix widgets or use different types of text.
If you don’t want the contents to be centered, use horizontal_top instead.
Example:
def horizontal_update_func(): heading("I'm horizontal") horizontal(horizontal_update_func)
- pyegui.horizontal_centered(update_fun)
Like horizontal, but allocates the full vertical height and then centers elements vertically.
- pyegui.horizontal_top(update_fun)
Like horizontal, but aligns content with top.
- pyegui.horizontal_wrapped(update_fun)
Start a ui with horizontal layout that wraps to a new row when it reaches the right edge of the max_size. After you have called this, the function registers the contents as any other widget.
Elements will be centered on the Y axis, i.e. adjusted up and down to lie in the center of the horizontal layout. The initial height is style.spacing.interact_size.y. Centering is almost always what you want if you are planning to mix widgets or use different types of text.
- pyegui.hyperlink(url)
A clickable hyperlink
Example:
hyperlink("https://github.com/emilk/egui")
- pyegui.hyperlink_to(label, url)
A clickable hyperlink with label
Example:
hyperlink_to("egui on GitHub", "https://www.github.com/emilk/egui/")
- pyegui.image(source, **kwargs)
Show an image available at the given uri.
Example:
image("https://picsum.photos/480") image("file://assets/ferris.png", max_height = 50, max_width = 50)
- pyegui.image_and_text_clicked(source, text)
Creates a button with an image to the left of the text
Example:
if image_and_text_clicked("https://picsum.photos/480", "click me"): print("clicked")
- pyegui.indent(update_fun)
Create a child ui which is indented to the right. Example:
def update_func(): heading("I'm indented") indent(update_func)
- pyegui.label(text)
Show some text.
Example:
label("some text")
- pyegui.link_clicked(label)
Clickable text, that looks like a hyperlink. To link to a web page, use hyperlink or hyperlink_to.
Example:
if link_clicked("egui on GitHub"): print("clicked on a fake link")
- pyegui.monospace(text)
Show monospace (fixed width) text.
Example:
monospace("hello")
- pyegui.progress(value)
A simple progress bar. value in the [0, 1] range, where 1 means “completed”.
Example:
progress(0.5)
- pyegui.radio_value(current_value, alternative, text)
Show a radio button. It is selected if current_value == selected_value. If clicked, selected_value is assigned to current_value.
Example:
RED = 0 GREEN = 1 BLUE = 2 c = Int(RED) radio_value(c, RED, "red") radio_value(c, GREEN, "green") radio_value(c, BLUE, "blue")
- pyegui.run_native(app_name, update_func, **kwargs)
Creates a window and runs update_func. This is an entrypoint for your GUI application.
- Args:
app_name (str): name displayed at the header bar
update_func (Callable[[Context], None]): your function that draws UI
inner_height (float): the desired height of the window
inner_width (float): the desired width of the window
min_inner_height (float): min height of the window
min_inner_width (float): min width of the window
max_inner_height (float): max height of the window
max_inner_width (float): max width of the window
fullscreen (bool): whether to open app in fullscreen
maximized (bool): whether to open app maximized
resizable (bool): whether our app is resizable
transparent (bool): whether our app is transparent
icon_path (str): path to icon in rgba format
Examples:
name = Str("") def update_func(ctx): heading(f"Hello, {name.value}!") text_edit_singleline(name) if button_clicked("click me"): print("clicked") run_native("My app", update_func)
- pyegui.scope(update_fun)
Create a scoped child ui.
You can use this to temporarily change the Style of a sub-region.
Example:
def update_func(): heading("0.5 opacity") set_opacity(0.5) heading("normal opacity") scope(update_func)
- pyegui.scroll_area_horizontal(update_fun)
Create a horizontal scroll area.
Example:
def update_func(): heading("hi") heading("there") # a lot of elements scroll_area_horizontal(update_func)
- pyegui.scroll_area_vertical(update_fun)
Create a vertical scroll area.
Example:
def update_func(): heading("hi") heading("there") # a lot of elements scroll_area_vertical(update_func)
- pyegui.selectable_value(current_value, alternative, text)
Show selectable text. It is selected if current_value == selected_value. If clicked, selected_value is assigned to current_value.
Example:
RED = 0 GREEN = 1 BLUE = 2 c = Int(RED) selectable_value(c, RED, "red") selectable_value(c, GREEN, "green") selectable_value(c, BLUE, "blue")
- pyegui.separator()
A visual separator. A horizontal or vertical line on layout.
Example:
separator()
- pyegui.set_invisible()
Calling set_invisible() will cause all further widgets to be invisible, yet still allocate space.
The widgets will not be interactive (set_invisible() implies disable()).
Once invisible, there is no way to make the Ui visible again.
Example:
set_invisible() heading("this will not be visible")
- pyegui.set_opacity(opacity)
Make the widget in this Ui semi-transparent.
opacity must be between 0.0 and 1.0, where 0.0 means fully transparent (i.e., invisible) and 1.0 means fully opaque. Example:
set_opacity(0.5)
- pyegui.slider_float(value, min, max, text)
Control float with a slider.
Example:
data = Float(5) # inside update_func slider_float(data, 0, 50, "slide me")
- pyegui.slider_int(value, min, max, text)
Control int with a slider.
Example:
data = Int(5) # inside update_func slider_int(data, 0, 50, "slide me")
- pyegui.small(text)
Show small text.
Example:
small("hello")
- pyegui.small_button_clicked(text)
Returns true if the small button was clicked this frame
Example:
if small_button_clicked("click me"): print("click me, my friend")
- pyegui.spinner()
A spinner widget used to indicate loading.
Example:
spinner()
- pyegui.strong(text)
Show text that stand out a bit (e.g. slightly brighter).
Example:
strong("hello")
- pyegui.text_edit_multiline(text, **kwargs)
Show multiline text field and update the text
Example:
text = Str("editable") # inside update func text_edit_multiline(text, hint_text="hint")
- pyegui.text_edit_singleline(text, **kwargs)
Show singleline text field and update the text
Example:
text = Str("editable") # inside update func text_edit_singleline(text, hint_text="hint me bro")
- pyegui.toggle_value(selected, text)
Acts like a checkbox, but looks like a selectable label.
Example:
data = Bool(false) # inside update_func toggle_value(data, "check me")
- pyegui.vertical(update_fun)
Start a ui with vertical layout. Widgets will be left-justified.
- pyegui.vertical_centered(update_fun)
Start a ui with vertical layout. Widgets will be horizontally centered.
- pyegui.vertical_centered_justified(update_fun)
Start a ui with vertical layout. Widgets will be horizontally centered and justified (fill full width).
- pyegui.weak(text)
Show text that is weaker (fainter color).
Example:
weak("hello")