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
  • DropDown

DropDown#

class DropDown(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

GtkDropDown is a widget that allows the user to choose an item from a list of options.

https://docs.gtk.org/gtk4/drop-down.png

The GtkDropDown displays the [selected]:obj:selected choice.

The options are given to GtkDropDown in the form of GListModel and how the individual options are represented is determined by a ListItemFactory. The default factory displays simple strings, and adds a checkmark to the selected item in the popup.

To set your own factory, use set_factory. It is possible to use a separate factory for the items in the popup, with set_list_factory.

GtkDropDown knows how to obtain strings from the items in a StringList; for other models, you have to provide an expression to find the strings via set_expression.

GtkDropDown can optionally allow search in the popup, which is useful if the list of options is long. To enable the search entry, use set_enable_search.

Here is a UI definition example for GtkDropDown with a simple model:

<object class="GtkDropDown">
  <property name="model">
    <object class="GtkStringList">
      <items>
        <item translatable="yes">Factory</item>
        <item translatable="yes">Home</item>
        <item translatable="yes">Subway</item>
      </items>
    </object>
  </property>
</object>

If a GtkDropDown is created in this manner, or with new_from_strings, for instance, the object returned from get_selected_item will be a StringObject.

To learn more about the list widget framework, see the overview.

CSS nodes#

GtkDropDown has a single CSS node with name dropdown, with the button and popover nodes as children.

Accessibility#

GtkDropDown uses the COMBO_BOX role.

Constructors#

class DropDown
classmethod new(model: ListModel | None = None, expression: Expression | None = None) → Widget#

Creates a new GtkDropDown.

You may want to call set_factory to set up a way to map its items to widgets.

Parameters:
  • model – the model to use

  • expression – the expression to use

classmethod new_from_strings(strings: list[str]) → Widget#

Creates a new GtkDropDown that is populated with the strings.

Parameters:

strings – The strings to put in the dropdown

Methods#

class DropDown
get_enable_search() → bool#

Returns whether search is enabled.

get_expression() → Expression | None#

Gets the expression set that is used to obtain strings from items.

See set_expression.

get_factory() → ListItemFactory | None#

Gets the factory that’s currently used to populate list items.

The factory returned by this function is always used for the item in the button. It is also used for items in the popup if list_factory is not set.

get_header_factory() → ListItemFactory | None#

Gets the factory that’s currently used to create header widgets for the popup.

Added in version 4.12.

get_list_factory() → ListItemFactory | None#

Gets the factory that’s currently used to populate list items in the popup.

get_model() → ListModel | None#

Gets the model that provides the displayed items.

get_search_match_mode() → StringFilterMatchMode#

Returns the match mode that the search filter is using.

Added in version 4.12.

get_selected() → int#

Gets the position of the selected item.

get_selected_item() → Object | None#

Gets the selected item. If no item is selected, None is returned.

get_show_arrow() → bool#

Returns whether to show an arrow within the widget.

Added in version 4.6.

set_enable_search(enable_search: bool) → None#

Sets whether a search entry will be shown in the popup that allows to search for items in the list.

Note that expression must be set for search to work.

Parameters:

enable_search – whether to enable search

set_expression(expression: Expression | None = None) → None#

Sets the expression that gets evaluated to obtain strings from items.

This is used for search in the popup. The expression must have a value type of str.

Parameters:

expression – a GtkExpression

set_factory(factory: ListItemFactory | None = None) → None#

Sets the GtkListItemFactory to use for populating list items.

Parameters:

factory – the factory to use

set_header_factory(factory: ListItemFactory | None = None) → None#

Sets the GtkListItemFactory to use for creating header widgets for the popup.

Added in version 4.12.

Parameters:

factory – the factory to use

set_list_factory(factory: ListItemFactory | None = None) → None#

Sets the GtkListItemFactory to use for populating list items in the popup.

Parameters:

factory – the factory to use

set_model(model: ListModel | None = None) → None#

Sets the GListModel to use.

Parameters:

model – the model to use

set_search_match_mode(search_match_mode: StringFilterMatchMode) → None#

Sets the match mode for the search filter.

Added in version 4.12.

Parameters:

search_match_mode – the new match mode

set_selected(position: int) → None#

Selects the item at the given position.

Parameters:

position – the position of the item to select, or INVALID_LIST_POSITION

set_show_arrow(show_arrow: bool) → None#

Sets whether an arrow will be displayed within the widget.

Added in version 4.6.

Parameters:

show_arrow – whether to show an arrow within the widget

Properties#

class DropDown
props.enable_search: bool#

The type of the None singleton.

props.expression: Expression#

The type of the None singleton.

props.factory: ListItemFactory#

The type of the None singleton.

props.header_factory: ListItemFactory#

The type of the None singleton.

Added in version 4.12.

props.list_factory: ListItemFactory#

The type of the None singleton.

props.model: ListModel#

The type of the None singleton.

props.search_match_mode: StringFilterMatchMode#

The type of the None singleton.

Added in version 4.12.

props.selected: int#

The type of the None singleton.

props.selected_item: Object#

The type of the None singleton.

props.show_arrow: bool#

The type of the None singleton.

Added in version 4.6.

Signals#

class DropDown.signals
activate() → None#

Emitted to when the drop down is activated.

The ::activate signal on GtkDropDown is an action signal and emitting it causes the drop down to pop up its dropdown.

Added in version 4.6.

On this page
  • CSS nodes
  • Accessibility
  • Constructors
    • DropDown.new()
    • DropDown.new_from_strings()
  • Methods
    • DropDown.get_enable_search()
    • DropDown.get_expression()
    • DropDown.get_factory()
    • DropDown.get_header_factory()
    • DropDown.get_list_factory()
    • DropDown.get_model()
    • DropDown.get_search_match_mode()
    • DropDown.get_selected()
    • DropDown.get_selected_item()
    • DropDown.get_show_arrow()
    • DropDown.set_enable_search()
    • DropDown.set_expression()
    • DropDown.set_factory()
    • DropDown.set_header_factory()
    • DropDown.set_list_factory()
    • DropDown.set_model()
    • DropDown.set_search_match_mode()
    • DropDown.set_selected()
    • DropDown.set_show_arrow()
  • Properties
    • DropDown.props.enable_search
    • DropDown.props.expression
    • DropDown.props.factory
    • DropDown.props.header_factory
    • DropDown.props.list_factory
    • DropDown.props.model
    • DropDown.props.search_match_mode
    • DropDown.props.selected
    • DropDown.props.selected_item
    • DropDown.props.show_arrow
  • Signals
    • DropDown.signals.activate()

This Page

  • Show Source

Created using Sphinx 8.2.3.

General Index

Built with the PyData Sphinx Theme 0.16.1.