controlwidget(3tk)
β¨ NAME β¨
controlwidget β a whole lil family of widgets for displaying and controlling numerical values π
π SYNOPSIS π
package require Tcl ?8.5?
package require Tk ?8.5?
package require snit ?2.0?
package require controlwidget ?0.1?
::controlwidget::meter w args
::controlwidget::slider w args
::controlwidget::equalizerBar w args
::controlwidget::thermometer w args
::controlwidget::voltmeter w args
::controlwidget::tachometer w args
::controlwidget::rdial w args
$widget get
$widget set value
::controlwidget::led w args
::controlwidget::radioMatrix w args
$led on
$led off
$led setstate state
$matrix get
$matrix set index
π DESCRIPTION π
okay so bestie, controlwidget is obsessed with one thing: showing numbers and letting you mess with them. It straight up copies the vibe of all the meters and controls you'd find in a lab π¬ β but also just, like, in your daily life? Volt meters, equalizers, tachometers, to name a few. Think of them as the cooler, glowed-up alternative to the plain scale widget. periodt.
β οΈ real talk though: this package has not been tested extensively so far. So if you use sizes that aren't the defaults, you might get a look that's... unexpected π. Also not every option for coloring the various parts, fonts, etc. has been tested, so that's another possible source of bugs. not me exposing my own package π
and one last note before we dive in: some parts haven't been given an option at all β most notably the colors of parts that need lighter and darker shades to cooperate with each other. so yeah, those just do their thing on their own π
π¦ TYPES OF WIDGETS π¦
The package keeps several types of widgets, and honestly the range is iconic:
- Vertical meters β your value gets translated into a vertical position, like those coloured bars on your stereo setup ποΈ
- Angle displays β your value maps to the angle of a needle, tachometer style π§
- Interactive widgets β most of them let you change the variable's value by pressing the mouse button on the needle and dragging it up/down or left/right π±οΈ
- Non-interactive widgets β some of them, like the thermometer widget, are just gonna stand there and not let you do that. read-only energy π§
- Logical or choice widgets β these show values either as on/off (or true/false), or as one of a discrete set of choices π
But here's what they all have in common, no cap:
- you can connect them to a variable, and changing the variable changes the display
- they all have the
setandgetmethods to interact with the value the widget displays β whether that value is stored in a global variable or not - their appearance and behaviour is determined by one or more options you can set at creation time, and often later on too. They're all built on the
snitpackage, so the methodsconfigureandcgetare available for setting and getting those options β¨
π COMMANDS π
Right now the package ships with these widgets of the vertical meter type:
π ::controlwidget::meter w args
Makes a vertical meter β an axis plus a moveable arrow. it's giving speedometer but upright π«
w(in) β name of the widget to be created.args(in) β list of key-value pairs controlling the appearance and behaviour of the widget:variablename β name of the variable to be associated with the meterbackgroundcolor β background color for the widgetheightpixels β height of the widgetwidthpixels β width of the widgetarrowthicknesspixels β thickness of the displayed arrow, in pixelsarrowcolorcolor β color of the displayed arrowreadonlyboolean β whether the arrow can be moved interactively or not
π ::controlwidget::slider w args
Makes a widget with one or more vertical sliders plus an axis. You can shift the slider handles interactively with the mouse β main character energy, honestly π«Ά
w(in) β name of the widget to be created.args(in) β list of key-value pairs controlling the appearance and behaviour of the widget:variablename β name of the (list) variable to be associated with the widgetnumberinteger β number of sliders in the widgetbackgroundcolor β background color for the widgetheightpixels β height of the widgetwidthpixels β width of the widgetsliderthicknesspixels β thickness of the slider handlessliderwidthcolor β width of the slider handlestroughwidthcolor β width of the troughs holding the sliders
π ::controlwidget::equalizerBar w args
Makes a widget with one or more vertical bars, exactly like the ones on hifi graphical equalizers π΅ Just know that it's a read-only widget, so no dragging bestie, only admiring.
w(in) β name of the widget to be created.args(in) β list of key-value pairs controlling the appearance and behaviour of the widget:variablename β name of the (list) variable to be associated with the widgetnumberinteger β number of bars in the widgetbackgroundcolor β background color for the widgetheightpixels β height of the widgetwidthpixels β width of the widgetbarwidthpixels β width of the barssegmentsinteger β number of segments the bars are divided insafecolorcolor β color for values lower than the warning levelwarningcolorcolor β color for values greater than the warning levelwarningleveldouble β threshold value, determines at what level the color changes
π ::controlwidget::thermometer w args
Makes a thermometer widget. yes it's read-only. no you cannot poke the mercury π‘οΈ
w(in) β name of the widget to be created.args(in) β list of key-value pairs controlling the appearance and behaviour of the widget:variablename β name of the (list) variable to be associated with the widgetbackgroundcolor β background color for the widgetheightpixels β height of the widgetwidthpixels β width of the widgetlinethicknesspixels β thickness of the line representing the "temperature"linecolorcolor β color of the line
π§ the axis options they ALL share
Every one of those widgets above uses a vertical axis, and they all have these options in common for configuring that axis:
axisformatstring β format string for formatting the numbers along the axisaxisfontstring β name of the font to be used for the numbersaxiscolorcolor β color of the axis (including the numbers)fromcolor β lower value for the axistocolor β upper value for the axismajorticksinteger β number of major tickmarks to draw (each one is labelled)minorticksinteger β number of minor tickmarks to draw between two major tickmarkslogboolean β use a logarithmic axis (true) or a linear axis (false)
The package also contains the following widget based on angle displays:
β ::controlwidget::voltmeter w args
Makes a voltmeter-like widget. the needle really does the most π₯
w(in) β name of the widget to be created.args(in) β list of key-value pairs controlling the appearance and behaviour of the widget:variablename β name of the variable to be associated with the metervaluevalue β value for the meter (if it's not associated with a variable)minvalue β the minimum value for data in the displaymaxvalue β the maximum value for data in the displaylabelslist β the labels to be shown along the scale. (these are simply considered texts, so no relation with the minimum and maximum perse)titlestring β string to be shown below the dialwidthpixels β the width of the widgetheightpixels β the height of the widgetborderwidthpixels β the width of the border surrounding the entire widgetreliefstring β the relief of the border surrounding the entire widgethighlightthicknesspixels β the width of the border to indicate the widget has keyboard focuslabelfontfontname β font of the labels to the scaletitlefontfontname β font of the title below the dialdialcolorcolor β color of the dial holding the needleneedlecolorcolor β color of the needlescalecolorcolor β color of the scale (arc and tickmarks)labelcolorcolor β color of the labels to the scaletitlecolorcolor β color of the title below the dial
β¨ ::controlwidget::tachometer w args
Create a tachometer-like widget. Itβs giving dashboard, but make it Tcl. ποΈπ¨
widgetw (in) β Name of the widget to be created.argumentsargs (in) β List of key-value pairs, controlling the appearance and behaviour of the widget. In addition to the ones given for the voltmeter widget:variablename β Name of the variable to be associated with the metervaluevalue β Value for the meter (if not associated with a variable)dangerlevelvalue β Level above which values are indicated with a different colordangercolorcolor β Color for the values above the "danger level"dangerwidthpixels β Width for the colored band indicating the "danger level"pincolorcolor β Color for the needle and the pin
β¨ ::controlwidget::rdial w args
Create a rotating dial. You can drag the dial to change the value. With the shift button depressed the value changes slowly, with the control button depressed it changes fast. Similarly, you can control the dial via the mouse wheel, with the shift and control button working in the same way as with the mouse pointer.
Note: The shift and control buttons currently have no effect on Windows.
widgetw (in) β Name of the widget to be created.argumentsargs (in) β List of key-value pairs, controlling the appearance and behaviour of the widget:variablename β Name of the variable to be associated with the dialvaluevalue β Value for the dial (if not associated with a variable)orientstring β Whether a horizontal disk/dial is required ("horizontal") or a vertical one ("vertical")stepvalue β Initial step for incrementing or decrementing the valuebindwheelvalue β Step size for controlling the dial's value via the mouse wheelslowvalue β Factor on the step size for incrementing or decrementing the value slowlyfastvalue β Factor on the step size for incrementing or decrementing the value fastscalevalue β Scale value to be applied to the actual valuecallbackcommand β Command to be called when the value changeswidthpixels β The width of the widgetheightpixels β The height of the widgetbackgroundcolor β The background color of the widget (coloring of the disk/dial)foregroundcolor β The foreground color of the widget (the marker lines)
All these widgets have the following methods:
$widget getβ Return the current value or values shown in the widget$widget set valueβ Reset the value or values shown in the widget. If the widget is associated with a variable, that variable is set as well.valuedouble/list β New value or values for the widget
Two further widgets are available, meant to display logical values:
π‘ ::controlwidget::led w args
Create a LED-like widget. tiny glow-up, literally. β¨
widgetw (in) β Name of the widget to be created.argumentsargs (in) β List of key-value pairs, controlling the appearance and behaviour of the widget. In addition to the ones given for the voltmeter widget:variablename β Name of the variable to be associated with the LEDsizepixels β Diameter of the LED widgetoncolor β Color to use for the "on" stateoffcolor β Color to use for the "off" state
ποΈ ::controlwidget::radioMatrix w args
Create a matrix of radio buttons that behaves as a single widget. bestie, itβs a whole grid of choices, no cap.
widgetw (in) β Name of the widget to be created.argumentsargs (in) β List of key-value pairs, controlling the appearance and behaviour of the widget. In addition to the ones given for the voltmeter widget:variablename β Name of the variable to be associated with the matrixorientstring β The way the radio buttons are to be arranged (horizontal or vertical first)rowsinteger β Number of rows in the matrixcolumnsinteger β Number of columns in the matrixcommandlist β Command associated with the radio buttons. Invoked when the active radio button changes.
The LED widget has the following public methods:
$led onβ Set the state to "on"$led offβ Set the state to "off"$led setstate stateβ Set the state according to the value of"state"stateboolean (in) β New state for the LED widget
The radioMatrix widget has two public methods:
$matrix getβ Return the index of the currently selected radio button$matrix set indexβ Select the radio button with index"index"indexinteger β Index of the radio button to be set
π ACKNOWLEDGMENTS π
The code for most of these widgets first appeared on the Wiki. In many cases, Arjen Markus merely refactored the code a bit and "snitified" some of them. The original code was developed by the following people:
- Vertical meter, LED display, radio matrix: Ron Fox
- Rotating dials: Gerhard Reithofer
- Voltmeter and tachometer: Marco Maggi
- Code for moving the needle: ?
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category controlwidget of the Tklib Trackers [http://core.tcl.tk/tklib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
π KEYWORDS π
controlling, displaying, numerical values, scale widget
π COPYRIGHT π
Copyright (c) 2010 Ron Fox <rfox@...> Copyright (c) 2010 Gerhard Reithofer <...@...> Copyright (c) 2010 Marco Maggi <...@...> Copyright (c) 2010 Arjen Markus <arjenmarkus@users.sourceforge.net>
okay bestie, thatβs the whole controlwidget(3tk) page from tklib 0.1 π the footer didnβt give a date, but you know Iβd timestamp it with sparkles if I could. stay iconic, keep those widgets slaying, and donβt forget to report bugs. periodt. π π¦
π¦ where this page comes from
- debian trixie: tklib 0.9-1
- ubuntu questing: tklib 0.9-1
- ubuntu resolute: tklib 0.9-1build1
- ubuntu stonking: tklib 0.9-1build1
- Copyright (c) 2010 Ron Fox <rfox@\&.\&.\&.>
- Copyright (c) 2010 Gerhard Reithofer <\&.\&.\&.@\&.\&.\&.>
- Copyright (c) 2010 Marco Maggi <\&.\&.\&.@\&.\&.\&.>
- Copyright (c) 2010 Arjen Markus <arjenmarkus@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms