Skip to main content
Ctrl+K

GNOME Python API

  • GLib
  • Gio
  • GObject
  • Gtk
  • Gdk
  • Adw
    • DBus
    • DBusGLib
    • Flatpak
    • GModule
    • Gcr
    • GdkPixbuf
    • GdkPixdata
    • GdkWayland
    • GdkX11
    • Graphene
    • Gsk
    • Gst
    • GstBase
    • GstCheck
    • GstController
    • GstNet
    • GtkSource
    • HarfBuzz
    • ICal
    • JavaScriptCore
    • Pango
    • PangoCairo
    • PangoFT2
    • PangoFc
    • PangoOT
    • PangoXft
    • Shumate
    • Soup
    • Vte
    • WebKit
    • WebKitWebProcessExtension
    • Xdp
    • XdpGtk4
    • pycairo
  • GLib
  • Gio
  • GObject
  • Gtk
  • Gdk
  • Adw
  • DBus
  • DBusGLib
  • Flatpak
  • GModule
  • Gcr
  • GdkPixbuf
  • GdkPixdata
  • GdkWayland
  • GdkX11
  • Graphene
  • Gsk
  • Gst
  • GstBase
  • GstCheck
  • GstController
  • GstNet
  • GtkSource
  • HarfBuzz
  • ICal
  • JavaScriptCore
  • Pango
  • PangoCairo
  • PangoFT2
  • PangoFc
  • PangoOT
  • PangoXft
  • Shumate
  • Soup
  • Vte
  • WebKit
  • WebKitWebProcessExtension
  • Xdp
  • XdpGtk4
  • pycairo

Section Navigation

API

  • Classes
    • ATContext
    • AboutDialog
    • ActionBar
    • ActivateAction
    • Adjustment
    • AlertDialog
    • AlternativeTrigger
    • AnyFilter
    • AppChooserButton
    • AppChooserDialog
    • AppChooserWidget
    • Application
    • ApplicationWindow
    • AspectFrame
    • Assistant
    • AssistantPage
    • BinLayout
    • BookmarkList
    • BoolFilter
    • Box
    • BoxLayout
    • Builder
    • Builder.BuilderScope
    • BuilderCScope
    • BuilderListItemFactory
    • Button
    • CClosureExpression
    • Calendar
    • CallbackAction
    • CellArea
    • CellAreaBox
    • CellAreaContext
    • CellRenderer
    • CellRendererAccel
    • CellRendererCombo
    • CellRendererPixbuf
    • CellRendererProgress
    • CellRendererSpin
    • CellRendererSpinner
    • CellRendererText
    • CellRendererToggle
    • CellView
    • CenterBox
    • CenterLayout
    • CheckButton
    • ClosureExpression
    • ColorButton
    • ColorChooserDialog
    • ColorChooserWidget
    • ColorDialog
    • ColorDialogButton
    • ColumnView
    • ColumnViewCell
    • ColumnViewColumn
    • ColumnViewRow
    • ColumnViewSorter
    • ComboBox
    • ComboBoxText
    • ConstantExpression
    • Constraint
    • ConstraintGuide
    • ConstraintLayout
    • ConstraintLayoutChild
    • CssProvider
    • CustomFilter
    • CustomLayout
    • CustomSorter
    • Dialog
    • DirectoryList
    • DragIcon
    • DragSource
    • DrawingArea
    • DropControllerMotion
    • DropDown
    • DropTarget
    • DropTargetAsync
    • EditableLabel
    • EmojiChooser
    • Entry
    • EntryBuffer
    • EntryCompletion
    • EventController
    • EventControllerFocus
    • EventControllerKey
    • EventControllerLegacy
    • EventControllerMotion
    • EventControllerScroll
    • EveryFilter
    • Expander
    • Expression
    • FileChooserDialog
    • FileChooserNative
    • FileChooserWidget
    • FileDialog
    • FileFilter
    • FileLauncher
    • Filter
    • FilterListModel
    • Fixed
    • FixedLayout
    • FixedLayoutChild
    • FlattenListModel
    • FlowBox
    • FlowBoxChild
    • FontButton
    • FontChooserDialog
    • FontChooserWidget
    • FontDialog
    • FontDialogButton
    • Frame
    • GLArea
    • Gesture
    • GestureClick
    • GestureDrag
    • GestureLongPress
    • GesturePan
    • GestureRotate
    • GestureSingle
    • GestureStylus
    • GestureSwipe
    • GestureZoom
    • GraphicsOffload
    • Grid
    • GridLayout
    • GridLayoutChild
    • GridView
    • HeaderBar
    • IMContext
    • IMContextSimple
    • IMMulticontext
    • IconPaintable
    • IconTheme
    • IconView
    • Image
    • InfoBar
    • Inscription
    • KeyvalTrigger
    • Label
    • LayoutChild
    • LayoutManager
    • LevelBar
    • LinkButton
    • ListBase
    • ListBox
    • ListBoxRow
    • ListHeader
    • ListItem
    • ListItemFactory
    • ListStore
    • ListView
    • LockButton
    • MapListModel
    • MediaControls
    • MediaFile
    • MediaStream
    • MenuButton
    • MessageDialog
    • MnemonicAction
    • MnemonicTrigger
    • MountOperation
    • MultiFilter
    • MultiSelection
    • MultiSorter
    • NamedAction
    • NativeDialog
    • NeverTrigger
    • NoSelection
    • Notebook
    • NotebookPage
    • NothingAction
    • NumericSorter
    • ObjectExpression
    • Overlay
    • OverlayLayout
    • OverlayLayoutChild
    • PadController
    • PageSetup
    • PageSetupUnixDialog
    • Paned
    • ParamSpecExpression
    • PasswordEntry
    • PasswordEntryBuffer
    • Picture
    • Popover
    • PopoverMenu
    • PopoverMenuBar
    • PrintContext
    • PrintDialog
    • PrintJob
    • PrintOperation
    • PrintSettings
    • PrintUnixDialog
    • Printer
    • ProgressBar
    • PropertyExpression
    • PyGTKDeprecationWarning
    • Range
    • RecentManager
    • Revealer
    • Scale
    • ScaleButton
    • Scrollbar
    • ScrolledWindow
    • SearchBar
    • SearchEntry
    • SelectionFilterModel
    • Separator
    • Settings
    • Shortcut
    • ShortcutAction
    • ShortcutController
    • ShortcutLabel
    • ShortcutTrigger
    • ShortcutsGroup
    • ShortcutsSection
    • ShortcutsShortcut
    • ShortcutsWindow
    • SignalAction
    • SignalListItemFactory
    • SingleSelection
    • SizeGroup
    • SliceListModel
    • Snapshot
    • SortListModel
    • Sorter
    • SpinButton
    • Spinner
    • Stack
    • StackPage
    • StackSidebar
    • StackSwitcher
    • Statusbar
    • StringFilter
    • StringList
    • StringObject
    • StringSorter
    • StyleContext
    • Switch
    • Template
    • Template.Callback
    • Template.Child
    • Text
    • TextBuffer
    • TextChildAnchor
    • TextMark
    • TextTag
    • TextTagTable
    • TextView
    • ToggleButton
    • Tooltip
    • TreeExpander
    • TreeListModel
    • TreeListRow
    • TreeListRowSorter
    • TreeModelFilter
    • TreeModelRow
    • TreeModelRowIter
    • TreeModelSort
    • TreeSelection
    • TreeStore
    • TreeView
    • TreeViewColumn
    • UriLauncher
    • Video
    • Viewport
    • VolumeButton
    • Widget
    • WidgetPaintable
    • Window
    • WindowControls
    • WindowGroup
    • WindowHandle
  • Interfaces
    • Accessible
    • AccessibleRange
    • AccessibleText
    • Actionable
    • AppChooser
    • Buildable
    • BuilderScope
    • CellEditable
    • CellLayout
    • ColorChooser
    • ConstraintTarget
    • Editable
    • FileChooser
    • FontChooser
    • Native
    • Orientable
    • PrintOperationPreview
    • Root
    • Scrollable
    • SectionModel
    • SelectionModel
    • ShortcutManager
    • StyleProvider
    • SymbolicPaintable
    • TreeDragDest
    • TreeDragSource
    • TreeModel
    • TreeSortable
  • Structures
    • AccessibleList
    • AccessibleTextRange
    • Bitset
    • BitsetIter
    • Border
    • BuildableParseContext
    • BuildableParser
    • CssLocation
    • CssSection
    • CssStyleChange
    • ExpressionWatch
    • PadActionEntry
    • PageRange
    • PaperSize
    • PrintBackend
    • PrintSetup
    • RecentData
    • RecentInfo
    • RequestedSize
    • Requisition
    • ScrollInfo
    • TextIter
    • TreeIter
    • TreePath
    • TreeRowData
    • TreeRowReference
  • Enums
    • AccessibleAnnouncementPriority
    • AccessibleAutocomplete
    • AccessibleInvalidState
    • AccessiblePlatformState
    • AccessibleProperty
    • AccessibleRelation
    • AccessibleRole
    • AccessibleSort
    • AccessibleState
    • AccessibleTextContentChange
    • AccessibleTextGranularity
    • AccessibleTristate
    • Align
    • ApplicationInhibitFlags
    • ArrowType
    • AssistantPageType
    • BaselinePosition
    • BorderStyle
    • BuilderClosureFlags
    • BuilderError
    • ButtonsType
    • CellRendererAccelMode
    • CellRendererMode
    • CellRendererState
    • Collation
    • ConstraintAttribute
    • ConstraintRelation
    • ConstraintStrength
    • ConstraintVflParserError
    • ContentFit
    • CornerType
    • CssParserError
    • CssParserWarning
    • DebugFlags
    • DeleteType
    • DialogError
    • DialogFlags
    • DirectionType
    • EditableProperties
    • EntryIconPosition
    • EventControllerScrollFlags
    • EventSequenceState
    • FileChooserAction
    • FileChooserError
    • FilterChange
    • FilterMatch
    • FontChooserLevel
    • FontLevel
    • FontRendering
    • GraphicsOffloadEnabled
    • IconLookupFlags
    • IconSize
    • IconThemeError
    • IconViewDropPosition
    • ImageType
    • InputHints
    • InputPurpose
    • InscriptionOverflow
    • Justification
    • LevelBarMode
    • License
    • ListScrollFlags
    • ListTabBehavior
    • MessageType
    • MovementStep
    • NaturalWrapMode
    • NotebookTab
    • NumberUpLayout
    • Ordering
    • Orientation
    • Overflow
    • PackType
    • PadActionType
    • PageOrientation
    • PageSet
    • PanDirection
    • PickFlags
    • PolicyType
    • PopoverMenuFlags
    • PositionType
    • PrintCapabilities
    • PrintDuplex
    • PrintError
    • PrintOperationAction
    • PrintOperationResult
    • PrintPages
    • PrintQuality
    • PrintStatus
    • PropagationLimit
    • PropagationPhase
    • RecentManagerError
    • ResponseType
    • RevealerTransitionType
    • ScrollStep
    • ScrollType
    • ScrollablePolicy
    • SelectionMode
    • SensitivityType
    • ShortcutActionFlags
    • ShortcutScope
    • ShortcutType
    • SizeGroupMode
    • SizeRequestMode
    • SortType
    • SorterChange
    • SorterOrder
    • SpinButtonUpdatePolicy
    • SpinType
    • StackTransitionType
    • StateFlags
    • StringFilterMatchMode
    • StyleContextPrintFlags
    • SymbolicColor
    • SystemSetting
    • TextBufferNotifyFlags
    • TextDirection
    • TextExtendSelection
    • TextSearchFlags
    • TextViewLayer
    • TextWindowType
    • TreeModelFlags
    • TreeViewColumnSizing
    • TreeViewDropPosition
    • TreeViewGridLines
    • Unit
    • WrapMode
  • Functions
  • Constants
  • Gtk
  • Classes
  • SearchBar

SearchBar#

class SearchBar(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

GtkSearchBar is a container made to have a search entry.

https://docs.gtk.org/gtk4/search-bar.png

It can also contain additional widgets, such as drop-down menus, or buttons. The search bar would appear when a search is started through typing on the keyboard, or the application’s search mode is toggled on.

For keyboard presses to start a search, the search bar must be told of a widget to capture key events from through set_key_capture_widget. This widget will typically be the top-level window, or a parent container of the search bar. Common shortcuts such as Ctrl+F should be handled as an application action, or through the menu items.

You will also need to tell the search bar about which entry you are using as your search entry using connect_entry.

Creating a search bar#

The following example shows you how to create a more complex search entry.

A simple example

Shortcuts and Gestures#

GtkSearchBar supports the following keyboard shortcuts:

  • Escape hides the search bar.

CSS nodes#

searchbar
╰── revealer
    ╰── box
         ├── [child]
         ╰── [button.close]

GtkSearchBar has a main CSS node with name searchbar. It has a child node with name revealer that contains a node with name box. The box node contains both the CSS node of the child widget as well as an optional button node which gets the .close style class applied.

Accessibility#

GtkSearchBar uses the SEARCH role.

Constructors#

class SearchBar
classmethod new() → Widget#

Creates a GtkSearchBar.

You will need to tell it about which widget is going to be your text entry using connect_entry.

Methods#

class SearchBar
connect_entry(entry: Editable) → None#

Connects the GtkEditable widget passed as the one to be used in this search bar.

The entry should be a descendant of the search bar. Calling this function manually is only required if the entry isn’t the direct child of the search bar (as in our main example).

Parameters:

entry – a GtkEditable

get_child() → Widget | None#

Gets the child widget of bar.

get_key_capture_widget() → Widget | None#

Gets the widget that bar is capturing key events from.

get_search_mode() → bool#

Returns whether the search mode is on or off.

get_show_close_button() → bool#

Returns whether the close button is shown.

set_child(child: Widget | None = None) → None#

Sets the child widget of bar.

Parameters:

child – the child widget

set_key_capture_widget(widget: Widget | None = None) → None#

Sets widget as the widget that bar will capture key events from.

If key events are handled by the search bar, the bar will be shown, and the entry populated with the entered text.

Note that despite the name of this function, the events are only ‘captured’ in the bubble phase, which means that editable child widgets of widget will receive text input before it gets captured. If that is not desired, you can capture and forward the events yourself with forward.

Parameters:

widget – a GtkWidget

set_search_mode(search_mode: bool) → None#

Switches the search mode on or off.

Parameters:

search_mode – the new state of the search mode

set_show_close_button(visible: bool) → None#

Shows or hides the close button.

Applications that already have a “search” toggle button should not show a close button in their search bar, as it duplicates the role of the toggle button.

Parameters:

visible – whether the close button will be shown or not

Properties#

class SearchBar
props.child: Widget#

The type of the None singleton.

props.key_capture_widget: Widget#

The type of the None singleton.

props.search_mode_enabled: bool#

The type of the None singleton.

props.show_close_button: bool#

The type of the None singleton.

On this page
  • Creating a search bar
  • Shortcuts and Gestures
  • CSS nodes
  • Accessibility
  • Constructors
    • SearchBar.new()
  • Methods
    • SearchBar.connect_entry()
    • SearchBar.get_child()
    • SearchBar.get_key_capture_widget()
    • SearchBar.get_search_mode()
    • SearchBar.get_show_close_button()
    • SearchBar.set_child()
    • SearchBar.set_key_capture_widget()
    • SearchBar.set_search_mode()
    • SearchBar.set_show_close_button()
  • Properties
    • SearchBar.props.child
    • SearchBar.props.key_capture_widget
    • SearchBar.props.search_mode_enabled
    • SearchBar.props.show_close_button

This Page

  • Show Source

Created using Sphinx 8.2.3.

General Index

Built with the PyData Sphinx Theme 0.16.1.