ttk::checkbutton(3tk)

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

✨ ttk::checkbutton ✨

okay bestie, welcome to the ttk::checkbutton page from the Tk Themed Widget manual β€” it's an on/off widget and it's literally the most iconic little toggle in the game πŸ’…


🌸 NAME 🌸

ttk::checkbutton β€” the on/off widget. that's it. that's the whole job. and it ate.


πŸŽ€ SYNOPSIS πŸŽ€

ttk::checkbutton pathName ?options?

πŸ¦‹ DESCRIPTION πŸ¦‹

so a ttk::checkbutton widget is what you use to show or change a setting. it's giving very demure, very mindful: two states, selected and deselected, and nothing else. no drama.

and here's the cute part β€” the state of the checkbutton can be linked to a Tcl variable. so the widget and your variable are basically in a situationship that actually works 🫢


⭐ STANDARD OPTIONS ⭐

these ones are inherited from the whole ttk widget family, and they are:

  • -class
  • -compound
  • -cursor
  • -image
  • -state
  • -style
  • -takefocus
  • -text
  • -textvariable
  • -underline
  • -width
for the full tea on all of these, go read the ttk_widget manual entry. she explains them way better than i could in a single bullet. πŸ’–

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

these are the options that are hers. hers specifically. nobody else's.

-command

  • Command-Line Name: -command
  • Database Name: command
  • Database Class: Command

a Tcl script to execute whenever the widget is invoked. that's the whole vibe β€” you click, she runs.

-offvalue

  • Command-Line Name: -offvalue
  • Database Name: offValue
  • Database Class: OffValue

the value that gets stored in the associated -variable when the widget is deselected. defaults to 0. yes, 0. classic.

-onvalue

  • Command-Line Name: -onvalue
  • Database Name: onValue
  • Database Class: OnValue

the value that gets stored in the associated -variable when the widget is selected. defaults to 1. slay.

-variable

  • Command-Line Name: -variable
  • Database Name: variable
  • Database Class: Variable

the name of a global variable whose value is linked to the widget. if you don't specify one, it defaults to the widget's pathname. so she'll just use her own name, main character energy fr fr πŸ‘‘


🌈 WIDGET COMMAND 🌈

okay so in addition to the standard cget, configure, identify element, instate, state and style commands (peep ttk::widget for those), checkbutton widgets also support this extra one:

  • pathname invoke β€” toggles between the selected and deselected states and evaluates the associated -command. if the widget is currently selected, it sets the -variable to the -offvalue and deselects the widget; otherwise, it sets the -variable to the -onvalue. it returns the result of the -command. πŸ’«

πŸ“ WIDGET STATES πŸ“

  • if the disabled state is set, the widget does not respond to user input. periodt.
  • the widget sets the selected state whenever the linked -variable is set to the widget's -onvalue, and clears it otherwise.
  • the widget sets the alternate state whenever the linked -variable is unset.
the alternate state is the one you use to show a "tri-state" or "indeterminate" selection, if you're feeling fancy. 🌸

🧚 STANDARD STYLES 🧚

Ttk::checkbutton widgets support the Toolbutton style in all standard themes, which is super handy if you're building widgets for toolbars. iykyk ✨


πŸ‘‘ STYLING OPTIONS πŸ‘‘

the class name for a ttk::checkbutton is TCheckbutton. noted.

Dynamic states: active, alternate, disabled, pressed, selected, readonly.

the TCheckbutton styling options you can configure with ttk::style are:

  • -background color
  • -compound compound
  • -foreground color
  • -indicatorbackground color
  • -indicatorcolor color
  • -indicatormargin padding
  • -indicatorrelief relief
  • -padding padding
ngl, some of these options are only available for specific themes. so if one isn't working, it's not you, it's the theme. πŸ™ˆ

for the full how-to on configuring ttk styles, go read the ttk::style manual page. she's the blueprint.


🫢 SEE ALSO 🫢


πŸ’… KEYWORDS πŸ’…

widget, button, toggle, check, option


and that's the whole page bestie!! ate and left no crumbs πŸ’–

this was Tk version 8.5, and yeah the page is ttk::checkbutton(3tk) β€” go toggle something, you got this 🌟

πŸ“¦ where this page comes from