controlwidget(n)
bestie, welcome to controlwidget(n) β part 1, and itβs giving βTk widgets but make it lab-core.β π β¨
β¨ NAME β¨
controlwidget β a whole collection of widgets for displaying and controlling numerical values.
π SYNOPSIS π
These are the package requirements and command shapes, literally exactly like this:
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 π
The controlwidget package is obsessed with displaying and interactively controlling numerical values. It mimics a bunch of meters and controls youβd find in lab settings, but also in daily life: volt meters, equalizers, and tachometers, to name a few. Think of them as alternatives for the scale widget. π₯
β οΈ Note: this package has not been extensively tested so far, and that may result in an unexpected appearance if you use sizes that are different than the defaults. Also, not all options for the coloring of the various parts and fonts and so on have been tested, so that may be another source of bugs. A last note: some parts have not been included in any option, most notably the colors of parts that require lighter and darker shades to cooperate.
π¦ TYPES OF WIDGETS π¦
The package distinguishes several types of widgets:
- Vertical meters: the value of the variable is translated into a vertical position, like with the coloured bars you find on your stereo installation.
- Angle displays: the value of the variable is related to the angle of a needle, like with tachometers.
- Interactive widgets: most widgets allow you to change the value of the variable by pressing the mouse button on the needle and shifting it up and down or left and right.
- Non-interactive widgets: some widgets, like the thermometer widget, do not allow such interaction.
- Logical or choice widgets: some widgets display the values as either on/off (or true/false) or as one of a set of discrete choices.
All widgets have in common, however, that you can connect them to a variable and that changing the variable changes the display. Furthermore, all widgets have the set and get methods to interact with the value that the widget displays (whether that is stored in a global variable or not). π«Ά
They also have in common that their appearance and behaviour is determined by one or more options that you can set at creation time and often later on as well. The widgets are all based on the snit package, so the methods configure and cget are available to set and get these options. π
π COMMANDS π
Currently the package contains these widgets of the vertical meter type:
ποΈ ::controlwidget::meter w args
Create a vertical meter consisting of an axis and a moveable arrow.
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 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
Create a widget containing one or more vertical sliders and an axis. You can shift the slider handles interactively via the mouse.
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 (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
Create a widget containing one or more vertical bars resembling those found on hifi graphical equalizers. Note that it is a read-only widget. π
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 (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
Create a thermometer widget (read-only).
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 (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
These widgets all use a vertical axis and have the following options in common for configuring the 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 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 contains the following widget based on angle displays:
π§ ::controlwidget::voltmeter w args
Create a voltmeter-like widget.
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 metervaluevalue β Value for the meter (if 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 π
Bestie, it's a tachometer. Like a speedometer but for your revs. Iconic little dial, very dashboard-chic. π
w(in) β Name of the widget to be created. Your baby needs a name, obviously.args(in) β List of key-value pairs that control the appearance and behaviour of the widget. It's everything the voltmeter widget takes plus these extra deluxe keys:variablename β Name of the variable to be associated with the meter.valuevalue β Value for the meter (use this if you're not associating it with a variable, iykyk).dangerlevelvalue β Level above which values get indicated with a different color. Drama mode: activated. π¨dangercolorcolor β The color used for values above the "danger level".dangerwidthpixels β Width of the colored band that shows off the "danger level".pincolorcolor β Color for the needle and the pin. Both of them. Coordinated. π
π‘ ::controlwidget::rdial w args π‘
A rotating dial, and yes you can literally drag it to change the value β main character interaction fr. Hold Shift and the value changes slowly; hold Ctrl and it changes fast. Same deal with the mouse wheel: the shift and control buttons do exactly the same thing there too. Obsessed with the consistency.
β οΈ Heads up bestie: the shift and control buttons currently have no effect on Windows. Not a vibe, but it's the truth.
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 dial.valuevalue β Value for the dial (for when there's no variable attached).orientstring β Whether you want a horizontal disk/dial ("horizontal") or a vertical one ("vertical"). Pick your aesthetic. π¦stepvalue β Initial step for incrementing or decrementing the value.bindwheelvalue β Step size for controlling the dial's value via the mouse wheel.slowvalue β Factor applied to the step size for incrementing or decrementing the value slowly.fastvalue β Factor applied to the step size for incrementing or decrementing the value fast.scalevalue β Scale value that gets applied to the actual value.callbackcommand β Command that gets called when the value changes. Gossip channel π¬.widthpixels β The width of the widget.heightpixels β The height of the widget.backgroundcolor β Background color of the widget (that's the coloring of the disk/dial itself).foregroundcolor β Foreground color of the widget (the marker lines).
π«Ά The methods literally all of these widgets share π«Ά
$widget get
Returns the current value (or values) shown in the widget. Simple. Slay.
$widget set value
Resets the value or values shown in the widget. Oh and β if the widget is associated with a variable, that variable gets set too. Two birds. β¨
valuedouble/list β New value or values for the widget.
π‘ Two more widgets, these ones are all about the logical values π‘
π ::controlwidget::led w args π
Creates a LED-like widget. Tiny light. Massive energy. β
w(in) β Name of the widget to be created.args(in) β List of key-value pairs controlling the appearance and behaviour of the widget. Again, everything the voltmeter widget takes, plus:variablename β Name of the variable to be associated with the LED.sizepixels β Diameter of the LED widget. Lil baby light or full-on beacon, your call.oncolor β Color to use for the"on"state.offcolor β Color to use for the"off"state.
π ::controlwidget::radioMatrix w args π
Creates a whole matrix of radio buttons that behaves as a single widget. Group project but make it functional. π
w(in) β Name of the widget to be created.args(in) β List of key-value pairs controlling the appearance and behaviour of the widget. Yep, you guessed it β everything from the voltmeter widget, plus:variablename β Name of the variable to be associated with the matrix.orientstring β The way the radio buttons are arranged (horizontal or vertical first).rowsinteger β Number of rows in the matrix.columnsinteger β Number of columns in the matrix.commandlist β Command associated with the radio buttons. Gets invoked when the active radio button changes. π
π The LED widget's public methods π
$led on
Sets the state to "on". LET THERE BE LIGHT. π₯
$led off
Sets the state to "off". Nap time. π΄
$led setstate state
Sets the state according to the value of "state".
stateboolean (in) β New state for the LED widget.
π§ The radioMatrix widget's two public methods π§
$matrix get
Returns the index of the currently selected radio button.
$matrix set index
Selects the radio button with index "index".
indexinteger β Index of the radio button to be set.
πΈ ACKNOWLEDGMENTS πΈ
Real ones only. The code for most of these widgets first appeared on the Wiki, and in many cases Arjen Markus merely refactored the code a bit and "snitified" some of them (his words, not mine, and honestly iconic behaviour). The original code was developed by these legends:
- Vertical meter, LED display, radio matrix: Ron Fox
- Rotating dials: Gerhard Reithofer
- Voltmeter and tachometer: Marco Maggi
- Code for moving the needle: ?
(The mystery dev. The main character we never met. π)
π BUGS, IDEAS, FEEDBACK π
Not gonna lie to you bestie, this document β and the package it describes β will undoubtedly contain bugs and other problems. Like, guaranteed. Please report them in the category controlwidget of the Tklib Trackers [http://core.tcl.tk/tklib/reportlist]. And please also report any ideas you may have for enhancements to either the package and/or the documentation. We want the glow-up. π«Ά
β 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 that's the whole page, bestie β you made it to the end! π This was controlwidget(n) from tklib, version 0.1, dated right there in the footer of the original. Go forth and build the prettiest little meters and dials and LED matrices anyone's ever seen. No cap. πβ¨π¦
π¦ where this page comes from
- alpine 3.24: tk-lib-doc 0.7-r0 Β· TCL
- 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-1017 on : a language model's rewrite of the original, under its terms