SourceClass Button
from egui import Buttonclass Button:Clickable button with text.
See also Ui.button.
Examples
import egui
def draw(ui: egui.Ui):
if ui.add(egui.Button("Click me")).clicked():
print("Clicked")
ui.add_enabled(False, egui.Button("Can't click this"))Methods§
Sourcedef atom_ui(self, /, ui: Ui) -> AtomLayoutResponse§
Show the button and return a WidgetAtomResponse for painting custom contents.
Sourcedef corner_radius(self, /, corner_radius: CornerRadius) -> Button§
Set the rounding of the button.
Sourcedef fill(self, /, fill: Color32) -> Button§
Override background fill color. Note that this will override any on-hover effects. Calling this will also turn on the frame.
Sourcedef frame(self, /, frame: bool) -> Button§
Turn off the frame
This adds either the built-in egui.Button.CLASS_FRAME or egui.Button.CLASS_NO_FRAME class.
With the default style, the latter removes the fill, the stroke and the margin.
Default: ui.visuals().button_frame.
Sourcedef frame_when_inactive(self, /, frame_when_inactive: bool) -> Button§
If False, the button will not have a frame when inactive.
This adds the built-in egui.Button.CLASS_HIDE_FRAME_WHEN_INACTIVE, which with the
default style removes the fill and the stroke, but keeps the margin, so the button does
not change size once the user interacts with it.
Default: True.
Note: When egui.Button.frame (or ui.visuals().button_frame) is False, this setting
has no effect.
@staticmethod
def from_atoms(atoms: Atoms) -> Button§
@staticmethod
def from_widget_text(text: WidgetText) -> Button§
Sourcedef gap(self, /, gap: float) -> Button§
Set the gap between atoms.
Source@staticmethod
def image(image_uri: str) -> Button§
Creates a button with an image. The size of the image as displayed is defined by the provided size.
Note: In contrast to Button(), this limits the image size to the default font height
(using egui.AtomExt.atom_max_height_font_size).
Source@staticmethod
def image_and_text(image_uri: str, text: Any) -> Button§
Creates a button with an image to the left of the text.
Note: In contrast to Button(), this limits the image size to the default font height
(using egui.AtomExt.atom_max_height_font_size).
Sourcedef image_tint_follows_text_color(self, /, image_tint_follows_text_color: bool) -> Button§
If true, use the widget text color as the fallback tint for images.
This makes sense for monochrome images that should have the same color as the text. It also
makes the image color depend on hover state. A non-white tint set on an image takes
precedence over this fallback; Color32.WHITE means untinted.
Default: False.
Sourcedef left_text(self, /, left_text: str) -> Button§
Show some text on the left side of the button.
Sourcedef min_size(self, /, min_size: Vec2) -> Button§
Set the minimum size of the button.
Source@staticmethod
def opt_image_and_text(image_uri: str |None = None, text: Any |None = None) -> Button§
Create a button with an optional image and optional text.
Note: In contrast to Button(), this limits the image size to the default font height
(using egui.AtomExt.atom_max_height_font_size).
Sourcedef right_text(self, /, right_text: str) -> Button§
Show some text on the right side of the button.
def rounding(self, /, corner_radius: CornerRadius) -> Button§
Source@staticmethod
def selectable(selected: bool, text: Any) -> Button§
Show a selectable button.
When selected, egui.Button.CLASS_SELECTED is added.
See also:
- Ui.selectable_value
- Ui.selectable_label
@staticmethod
def selectable_widget_text(selected: bool, text: WidgetText) -> Button§
Sourcedef selected(self, /, selected: bool) -> Button§
If True, mark this button as "selected".
Calling this method opts the button into toggle semantics and the
current pressed/not-pressed state will be reported to assistive
technologies (e.g. screen readers). Plain buttons that never call
selected are not announced as toggles.
When selected, egui.Button.CLASS_SELECTED is added. You should prefer calling this though over
just adding egui.Button.CLASS_SELECTED manually, since this also exposes accessibility information.
Sourcedef sense(self, /, sense: Sense) -> Button§
By default, buttons senses clicks.
Change this to a drag-button with Sense.drag().
Sourcedef shortcut_text(self, /, shortcut_text: str) -> Button§
Show some text on the right side of the button, in weak color.
Designed for menu buttons, for setting a keyboard shortcut text (e.g. Ctrl+S).
The text can be created with egui.Context.format_shortcut.
See also egui.Button.right_text.
def show(self, /, ui: Ui) -> Response§
Sourcedef small(self, /) -> Button§
Make this a small button, suitable for embedding into text.
This adds the built-in egui.Button.CLASS_SMALL, which with the default style removes the top and
bottom margin.
Sourcedef stroke(self, /, stroke: Stroke) -> Button§
Override button stroke. Note that this will override any on-hover effects. Calling this will also turn on the frame.
Sourcedef truncate(self, /) -> Button§
def with_class(self, /, class: str) -> Button§
def with_class_if(self, /, class: str, condition: bool) -> Button§
Sourcedef wrap(self, /) -> Button§
Sourcedef wrap_mode(self, /, wrap_mode: TextWrapMode) -> Button§
Set the wrap mode for the text.
By default, egui.Ui.wrap_mode will be used, which can be overridden with egui.Style.wrap_mode.
Note that any \n in the text will always produce a new line.