Post

ComboBox

ComboBox

SimpleKivy.SimpleKivy.ComboBox(text='choice0', values=('choice0', 'choice1'), enable_events=True, on_event='text', hint_text='', focus=False, button_width=32, k=None, dark=False, flat=False, **kwargs)

ComboBox.png

ComboBox.2.png

Creates a ComboBox widget (editable TextInput with a DropDown of values to choose from).

Dynamic Creation Parameters

flat: bool

Whether the dropdown button will have a flat style (see FlatButton):

  • False: Classic kivy widget style.
  • True: A FlatButton is used as the dropdown button.

Default is False.

dark: bool

Whether the textinput will have a dark style (see TextInputDark):

  • False: Classic kivy widget style.
  • True: A TextInputDark widget is used as the textinput.

Default is False.

Parameters

text: str

Text value shown when created.

  • str: Text string.

Default is "choice0"

hint_text: str

Hint text of the widget. Shown if text is empty.

  • str: Text string.

focus: bool

Wheter widget has focus in the textinput area when created.

  • True: TextInput is focused when created.
  • False: TextInput is not focused when created.

Default is False

values: list or sequence

A sequence where each element is a string representing the value choices.

  • [str, str, ...]: List of strings.

Default value is ('choice0', 'choice1')

size_behavior: str

Defines special bindings for the behavior of text_size and size:

  • "none": No binding between text_size and widget size.
  • "normal": Binds text_size to widget size.
  • "text" or "textv": This widgets’s height will be set to the text content.
  • "texth": This widgets’s width will be set to the text content.

Default is “normal”.

k: None, str, or NOTKEY

Key specification for quick acess:

  • None: Automatically sets an int value.
  • str: Use specific string key.
  • NOTKEY: Special flag indicating no key should be used.

size: str or sequence of 2 ints

Size specification of the widget:

  • str: "x{width}": Sets widget width and size_hint_x = None.
  • str: "y{height}": Sets widget height and size_hint_y = None.
  • str: "xchildren": Sets size_hint_x = None and binds this widget’s width to the sum of the widths of its children.
  • str: "ychildren": Sets size_hint_y = None and binds this widget’s height to the sum of the heights of its children.
  • str: "xchild_max": Sets size_hint_x = None and binds this widget’s width to the child with the maximum width.
  • str: "ychild_max": Sets size_hint_y = None and binds this widget’s height to the child with the maximum height.

You can combine up to two of the above size string specifications.

  • str: "{number}": Processed as size = (number, number) and size_hint = (None,None). Cannot be combined with other string specifications.
  • sequence: (int, int): Size of the widget. Same as Kivy. Has no effect if size_hint argument is not set to None.

Example:

1
2
3
4
5
6
7
sk.ComboBox(size = "y35")
sk.ComboBox(size = "x120y35")
sk.ComboBox(size = "xchildreny40")
sk.ComboBox(size = "xchildrenychildren")
sk.ComboBox(size = "xchild_maxy40")
sk.ComboBox(size = "60")
sk.ComboBox(size = (120,35), size_hint = (None, None))

enable_events: bool

Whether the widget will send events to the event_manager set in MyApp using the widgets k/id property as event identifier.

  • True: Triggers events.
  • False: Doesn’t trigger events.

on_event: str, iterable (tuple or list), dict

Defines which events/property changes will trigger the event_manager. Only has effect if enable_events = True.

  • str: Name of the event or property that will trigger the event_manager.
  • iterable: [str, str, ...]: Will trigger events for each name in the iterable.
  • dict: {"{event_name}": callback}: Calls instance.bind(**on_event) during widget creation.

Example:

1
2
3
4
5
sk.ComboBox(enable_events = True, on_event = 'width')
sk.ComboBox(enable_events = True, on_event = 'on_touch_down')
sk.ComboBox(enable_events = True, on_event = ['width','height','pos'])
sk.ComboBox(enable_events = True, on_event = {"size": lambda ins,v: print("size =",v)})

do_dot_subevent: bool

Adds a “.” to describe the event when triggering the event_manager.

  • True: The event identifier is str(widget.id)+".{event_name}".
  • False: The event identifier is the same as the widget’s k/id.

Default is False.

Returns

ComboBox widget created dynamically with the following modifications:

Properties

text (StringProperty) values (ListProperty) focus (AliasProperty)

Events

on_values(ins,val): Fired when changing the values property.

Kivy Bases

  • BoxLayout
    • TextInput
    • Button

This page only details the new or modified features. All other parameters inherit from the base Kivy widgets and can be found in the official Kivy documentation.

This post is licensed under CC BY 4.0 by the author.