:right-sidebar: True LinkButton =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: LinkButton(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.Button`, :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.Actionable`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget` A ``GtkLinkButton`` is a button with a hyperlink. .. image:: https://docs.gtk.org/gtk4/link-button.png It is useful to show quick links to resources. A link button is created by calling either :obj:`~gi.repository.Gtk.LinkButton.new` or :obj:`~gi.repository.Gtk.LinkButton.new_with_label`. If using the former, the URI you pass to the constructor is used as a label for the widget. The URI bound to a ``GtkLinkButton`` can be set specifically using :obj:`~gi.repository.Gtk.LinkButton.set_uri`. By default, ``GtkLinkButton`` calls :obj:`~gi.repository.Gtk.FileLauncher.launch` when the button is clicked. This behaviour can be overridden by connecting to the :obj:`~gi.repository.Gtk.LinkButton.signals.activate_link` signal and returning :const:`True` from the signal handler. CSS nodes --------- ``GtkLinkButton`` has a single CSS node with name button. To differentiate it from a plain ``GtkButton``, it gets the .link style class. Accessibility ------------- ``GtkLinkButton`` uses the :const:`~gi.repository.Gtk.AccessibleRole.LINK` role. Constructors ------------ .. rst-class:: interim-class .. class:: LinkButton :no-index: .. classmethod:: new(uri: str) -> ~gi.repository.Gtk.Widget Creates a new ``GtkLinkButton`` with the URI as its text. :param uri: a valid URI .. classmethod:: new_with_label(uri: str, label: str | None = None) -> ~gi.repository.Gtk.Widget Creates a new ``GtkLinkButton`` containing a label. :param uri: a valid URI :param label: the text of the button Methods ------- .. rst-class:: interim-class .. class:: LinkButton :no-index: .. method:: get_uri() -> str Retrieves the URI of the ``GtkLinkButton``. .. method:: get_visited() -> bool Retrieves the “visited” state of the ``GtkLinkButton``. The button becomes visited when it is clicked. If the URI is changed on the button, the “visited” state is unset again. The state may also be changed using :obj:`~gi.repository.Gtk.LinkButton.set_visited`. .. method:: set_uri(uri: str) -> None Sets ``uri`` as the URI where the ``GtkLinkButton`` points. As a side-effect this unsets the “visited” state of the button. :param uri: a valid URI .. method:: set_visited(visited: bool) -> None Sets the “visited” state of the ``GtkLinkButton``. See :obj:`~gi.repository.Gtk.LinkButton.get_visited` for more details. :param visited: the new “visited” state Properties ---------- .. rst-class:: interim-class .. class:: LinkButton :no-index: .. attribute:: props.uri :type: str The URI bound to this button. .. attribute:: props.visited :type: bool The 'visited' state of this button. A visited link is drawn in a different color. Signals ------- .. rst-class:: interim-class .. class:: LinkButton.signals :no-index: .. method:: activate_link() -> bool Emitted each time the ``GtkLinkButton`` is clicked. The default handler will call :obj:`~gi.repository.Gtk.FileLauncher.launch` with the URI stored inside the :obj:`~gi.repository.Gtk.LinkButton.props.uri` property. To override the default behavior, you can connect to the ::activate-link signal and stop the propagation of the signal by returning :const:`True` from your handler.