ttk::combobox(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– ttk::combobox β€” the manual page, but make it cute πŸ’–

okay so bestie, you're reading ttk::combobox(3tk) from the Tk Themed Widget family, and honestly? she's iconic. let's get into it 🫢


✨ NAME ✨

ttk::combobox β€” a text field with a popdown selection list. that's it, that's the vibe. text field + dropdown = the moment. πŸ’…


🌸 SYNOPSIS 🌸

ttk::combobox pathName ?options?

πŸ¦‹ DESCRIPTION πŸ¦‹

So a ttk::combobox literally combines a text field with a pop-down list of values. the user can pick the value of the text field from among the values in that list. it's giving "type it yourself OR let me hand you a menu," and honestly, main character energy. πŸ‘‘


⭐ STANDARD OPTIONS ⭐

these are the standard girlies, and they show up like:

  • -class
  • -cursor
  • -takefocus
  • -style
  • -placeholder
  • -placeholderforeground
go check the ttk_widget manual entry for the deets on all these standard options, iykyk πŸ“–

πŸ’œ WIDGET-SPECIFIC OPTIONS πŸ’œ

these are the ones that are hers specifically. slay. each one comes with a command-line name, a database name and a database class, so i'm giving you all three, no cap:

  • -exportselection β€” Database name: exportSelection, database class: ExportSelection. this one's a boolean value, and if it's set, the widget selection is linked to the X selection. πŸ”—
  • -justify β€” Database name: justify, database class: Justify. says how the text is aligned inside the widget. has to be one of left, center, or right. pick your fighter ✨
  • -height β€” Database name: height, database class: Height. the height of the pop-down listbox, measured in rows. πŸ“
  • -postcommand β€” Database name: postCommand, database class: PostCommand. a Tcl script that gets evaluated immediately before displaying the listbox. fun fact: the -postcommand script may specify the -values to display. sneaky but valid πŸ’…
  • -state β€” Database name: state, database class: State. one of normal, readonly, or disabled. in the readonly state, the value may not be edited directly, and the user can only select one of the -values from the dropdown list. in the normal state, the text field is directly editable. in the disabled state, no interaction is possible. (disabled = she's not taking questions today 😭)
  • -textvariable β€” Database name: textVariable, database class: TextVariable. the name of a global variable whose value is linked to the widget value. whenever the variable changes value the widget value is updated, and vice versa. it's a two-way situationship fr fr πŸ’ž
  • -values β€” Database name: values, database class: Values. the list of values to display in the drop-down listbox. πŸ“‹
  • -width β€” Database name: width, database class: Width. an integer value indicating the desired width of the entry window, in average-size characters of the widget's font. πŸ“

πŸŽ€ WIDGET COMMAND πŸŽ€

besides the standard cget, configure, identify element, instate, state and style commands (peep ttk::widget for those), combobox widgets support these extra commands:

  • pathName current ?newIndex? β€” if newIndex is supplied, sets the combobox value to the element at position newIndex in the list of -values. and bestie, in addition to integers, the end index is supported and indicates the last element of the list β€” moreover the same simple interpretation as for the command string index is supported, with simple integer index arithmetic and indexing relative to end. otherwise, it returns the index of the current value in the list of -values, or {} if the current value does not appear in the list. πŸ‘€
  • pathName get β€” returns the current value of the combobox.
  • pathName set value β€” sets the value of the combobox to value.

and the combobox widget also supports the following ttk::entry widget commands:

  • bbox
  • delete
  • icursor
  • index
  • insert
  • selection
  • xview

πŸ”₯ VIRTUAL EVENTS πŸ”₯

the combobox widget generates a <<ComboboxSelected>> virtual event when the user selects an element from the list of values. and if the selection action unposts the listbox, this event is delivered after the listbox is unposted. timing is everything, periodt ⏰


🌈 STYLING OPTIONS 🌈

the class name for a ttk::combobox is TCombobox. the ttk::combobox uses the entry and listbox widgets internally, and the listbox frame has a class name of ComboboxPopdownFrame.

Dynamic states: disabled, focus, pressed, readonly.

TCombobox styling options configurable with ttk::style are:

  • -arrowcolor color
  • -arrowsize amount
  • -background color
  • -bordercolor color
  • -darkcolor color
  • -focusfill color
  • -foreground color
  • -fieldbackground color β€” can only be changed when using non-native and non-graphical themes. (so like, read the room and check your theme first πŸ™ˆ)
  • -insertcolor color
  • -insertwidth amount
  • -lightcolor color
  • -padding padding
  • -placeholderforeground color
  • -postoffset padding
  • -selectbackground color β€” text entry select background.
  • -selectforeground color β€” text entry select foreground.

🧚 the popdown listbox situation 🧚

the ttk::combobox popdown listbox cannot be configured using ttk::style nor via the widget configure command. instead, the listbox can be configured using the option database:

option add *TCombobox*Listbox.background color
option add *TCombobox*Listbox.font font
option add *TCombobox*Listbox.foreground color
option add *TCombobox*Listbox.selectBackground color
option add *TCombobox*Listbox.selectForeground color

to configure a specific listbox (subject to future change β€” lowkey a warning bestie, this could shift on you):

set popdown [ttk::combobox::PopdownWindow .mycombobox]
$popdown.f.l configure -font font

πŸ’« ComboboxPopdownFrame styling πŸ’«

ComboboxPopdownFrame styling options configurable with ttk::style are:

  • -borderwidth amount
  • -relief relief

some options are only available for specific themes, so if something's not working, it might just be a theme thing, not a you thing 🫢

see the ttk::style manual page for information on how to configure ttk styles. go read it, it's required reading bestie πŸ“š

πŸ‘‘ SEE ALSO πŸ‘‘

  • ttk::widget(3tk)
  • ttk::entry(3tk)

🌟 KEYWORDS 🌟

choice, entry, list box, text box, widget


okay that's the whole page!! and for the sign-off: this lil masterpiece comes from Tk, version 8.5 β€” that's the source and the version and the date all rolled into one cute lil footer. stay hydrated, go configure your combobox, and remember: <rainbow>you ate</rainbow>. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from